通过下面的表格可以详细查看栅格系统如何在多种不同屏幕大小的设备上工作的。
超小屏幕 <576px |
小屏幕 ≥576px |
中等屏幕 ≥768px |
大屏幕 ≥992px |
超大屏 ≥1200px |
|
---|---|---|---|---|---|
最大宽度 | None (自动) | 540px | 720px | 960px | 1140px |
类前缀 | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
# 列数 | 12 | ||||
槽宽 | 30px (每列左右均有 15px 的 padding) | ||||
可嵌套 | 是 | ||||
是 |
网格类适用于屏幕宽度大于或等于断点大小的设备,并覆盖针对较小设备的网格类。 因此,应用任何
.col-md-
一个元素的类不仅会影响其在中型设备上的风格,而且还会影响其在大型设备上的风格
.col-lg-
元素内即可。
How it works Bootstrap’s grid system uses a series of containers, rows, and columns to layout and align content. It’s built with flexbox and is fully responsive. Below is an example and an in-depth look at how the grid comes together.
<div class="container"> <div class="row"> <div class="col-sm"> One of three columns </div> <div class="col-sm"> One of three columns </div> <div class="col-sm"> One of three columns </div> </div> </div>
The above example creates three equal-width columns on small, medium, large, and extra large devices using our predefined grid classes. Those columns are centered in the page with the parent .container
.
Breaking it down, here’s how it works:
.container
for a responsive pixel width or .container-fluid
for width: 100%
across all viewport and device sizes.padding
(called a gutter) for controlling the space between them. This padding
is then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side.width
will automatically layout as equal width columns. For example, four instances of .col-sm
will each automatically be 25% wide from the small breakpoint and up. See the auto-layout columns section for more examples..col-4
.width
s are set in percentages, so they’re always fluid and sized relative to their parent element.padding
to create the gutters between individual columns, however, you can remove the margin
from rows and padding
from columns with .no-gutters
on the .row
..col-sm-4
applies to small, medium, large, and extra large devices, but not the first xs
breakpoint)..col-4
) or Sass mixins for more semantic markup.