如何添加边缘顶部类="行"元素使用twitter引导框架?
当前回答
如果您只想在一个页面上更改,请添加以下样式规则:
#myCustomDivID .row {
margin-top:20px;
}
其他回答
在Twitter引导中编辑或重写行是一个坏主意,因为这是页面脚手架的核心部分,您将需要没有顶部边距的行。
要解决这个问题,可以创建一个新类“top-buffer”,添加所需的标准裕度。
.top-buffer { margin-top:20px; }
然后在需要上边距的行div上使用它。
<div class="row top-buffer"> ...
如果您只想在一个页面上更改,请添加以下样式规则:
#myCustomDivID .row {
margin-top:20px;
}
有一个技巧可以自动为容器中的第2 +行添加边距。
.container-row-margin .row + .row {
margin-top: 1rem;
}
将.container-row-margin添加到容器中,结果如下:
完整的HTML:
<div class="bg-secondary text-white">
div outside of the container.
</div>
<div class="container container-row-margin">
<div class="row">
<div class="col col-4 bg-warning">
Row without top margin
</div>
</div>
<div class="row">
<div class="col col-4 bg-primary text-white">
Row with top margin
</div>
</div>
<div class="row">
<div class="col col-4 bg-primary text-white">
Row with top margin
</div>
</div>
</div>
<div class="bg-secondary text-white">
div outside of the container.
</div>
取自官方样品。
我将这些类添加到引导样式表中
.voffset { margin-top: 2px; }
.voffset1 { margin-top: 5px; }
.voffset2 { margin-top: 10px; }
.voffset3 { margin-top: 15px; }
.voffset4 { margin-top: 30px; }
.voffset5 { margin-top: 40px; }
.voffset6 { margin-top: 60px; }
.voffset7 { margin-top: 80px; }
.voffset8 { margin-top: 100px; }
.voffset9 { margin-top: 150px; }
例子
<div class="container">
<div class="row voffset2">
<div class="col-lg-12">
<p>
Vertically offset text.
</p>
</div>
</div>
</div>
你可以使用下面的类进行引导4:
mt-0 mt-1 mt-2 mt-3 mt-4 ...
裁判:https://v4-alpha.getbootstrap.com/utilities/spacing/