我需要在div
的class
属性中有一个margin top
。我该怎么做?
<div class="mb-md-3 ml-md-3 col-lg-8" >
<!-- <div class="mb-md-3 ml-md-3 col-lg-8" > -->
<a href="<?php echo base_url();?>admin/admin/add_hospital">
<button class="btn btn-success" onclick="add_hospital()">
<i class="fas fa-plus"></i> Add Hospital
</button>
</a>
</div>
如您所见:
https://getbootstrap.com/docs/4.0/utilities/spacing/
看起来mb
和ml
指的是margin-bottom
和margin-left
我不是 Bootstrap 专家,但也许你可以尝试使用类似 mt-0
至于班级:
.mt-0 {
margin-top: 0 !important;
}
应该将边距顶部设置为 0,否则只需使用重要属性创建自己的类
编辑:
看起来 Bootstrap 在某个时候将一些边距设置为自动:
此外,Bootstrap 还包括一个 .mx-auto 类,用于通过将水平边距设置为 auto,水平居中固定宽度块级内容(即设置了 display: 块和宽度的内容)。
希望这有帮助
Bootstrap 提供用于设计 Web 的内置类。
例子
.mt-0 {
margin-top: 0 !important;
}
.ml-1 {
margin-left: 0.25rem !important;
}
.px-2 {
padding-left: 0.5rem !important;
padding-right: 0.5rem !important;
}
.p-3 {
padding: 0.75rem!important;
}
用法
<div class="mx-auto" style="width: 200px;">
Centered element
</div>
负边距
.mt-n1 {
margin-top: -0.25rem !important;
}
用法
<div class="row mx-md-n5">
<div class="col py-3 px-md-5 border bg-light">Custom column padding</div>
<div class="col py-3 px-md-5 border bg-light">Custom column padding</div>
</div>
更多参考