Bootstrap 4 网格 - 超大屏幕
XLarge 网格示例
超小屏 | 小 | 中 | 大 | 特大尺寸 | |
---|---|---|---|---|---|
类前缀 | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
屏幕宽度 | <576px | >=576px | >=768px | >=992px | >=1200px |
在上一章中,我们展示了一个适用于小屏幕和中等屏幕设备的网格示例。我们使用了两个 div(列),在小屏幕设备上将它们分割为 25%/75%,在中等屏幕设备上分割为 50%/50%,在大屏幕设备上分割为 33%/66%。
<div class="col-sm-3 col-md-6 col-lg-4">....</div>
<div class="col-sm-9 col-md-6 col-lg-8">....</div>
但在超大屏幕设备上,20%/80% 的分割可能更好。
超大屏幕设备定义为屏幕宽度从 1200 像素及以上。
对于超大屏幕设备,我们将使用 .col-xl-*
类。
<div class="col-sm-3 col-md-6 col-lg-4 col-xl-2">....</div>
<div class="col-sm-9 col-md-6 col-lg-8 col-xl-10">....</div>
下面的示例将在小屏幕设备上产生 25%/75% 的分割,在中等屏幕设备上产生 50%/50% 的分割,在大屏幕设备上产生 33%/66% 的分割,在超大屏幕设备上产生 20%/80% 的分割。在超小屏幕设备上,它将自动堆叠(100%)。
col-sm-3 col-md-6 col-lg-4 col-xl-2
col-sm-9 col-md-6 col-lg-8 col-xl-10
示例
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4 col-xl-2">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 col-md-6 col-lg-8 col-xl-10">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
自己动手试一试 »
注意:确保总和始终为 12。
仅使用 XLarge
在下面的示例中,我们只指定了 .col-xl-6
类(不包含 .col-lg-*
、.col-md-*
和/或 .col-sm-*
)。这意味着超大屏幕设备将分割为 50%/50%。但是,对于大、中、小以及超小屏幕设备,它们将垂直堆叠(100% 宽度)。
示例
<div class="container-fluid">
<div class="row">
<div class="col-xl-6">
<p>Lorem ipsum...</p>
</div>
<div class="col-xl-6">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
自己动手试一试 »
自动布局列
在 Bootstrap 4 中,有一种简单的方法可以为所有设备创建等宽列:只需从 .col-xl-*
中删除数字,并在指定的 **col 元素**数量上只使用 .col-xl
类。Bootstrap 将识别有多少列,每列将获得相同的宽度。
如果屏幕尺寸小于 1200 像素,列将水平堆叠。
<!-- 两列:超大屏幕及以上为 50% 宽度-->
<div class="row">
<div class="col-xl">1 of 2</div>
<div class="col-xl">2 of 2</div>
</div>
<!-- 四列:超大屏幕及以上为 25% 宽度 -->
<div class="row">
<div class="col-xl">1 of 4</div>
<div class="col-xl">2 of 4</div>
<div class="col-xl">3 of 4</div>
<div class="col-xl">4 of 4</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4