Approach 1 (offsets):
The first approach uses Bootstrap's own offset classes so it requires no change in markup and no extra CSS. The key is to set an offset equal to half of the remaining size of the row. So for example, a column of size 2 would be centered by adding an offset of 5, that's (12-2)/2.
In markup this would look like:
<div class="row">
<div class="col-md-2 col-md-offset-5"></div>
</div>
Now, there's an obvious drawback for this method, it only works for even column sizes, so only .col-X-2, .col-X-4, col-X-6, col-X-8 and col-X-10 are supported.
本文介绍了一种利用Bootstrap自带的偏移类来居中列的方法,无需额外CSS,仅通过设置列的大小一半作为偏移量实现。例如,.col-md-2的列可通过添加col-md-offset-5来居中。但此方法仅适用于偶数列大小,如.col-X-2,.col-X-4等。
4588

被折叠的 条评论
为什么被折叠?



