Bootstrap4 网格 小的


小网格示例

  Extra small Small Medium Large Extra Large
Class prefix .col- .col-sm- .col-md- .col-lg- .col-xl-
Screen width <576px >=576px >=768px >=992px >=1200px

假设我们有一个包含两列的简单布局。对于小型设备,我们希望将列拆分 25%/75%。

小型设备被定义为屏幕宽度为576 像素至 767 像素

对于小型设备,我们将使用.col-sm-*类。

我们将以下类添加到我们的两列中:

<div class="col-sm-3">....</div>
<div class="col-sm-9">....</div>

现在 Bootstrap 会显示"at the small size, look for classes with -sm- in them and use those"。

以下示例将导致小型(以及中型、大型和超大)设备上的 25%/75% 分割。在超小型设备上,它将自动堆叠(100%):

.col-sm-3
.col-sm-9

示例

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3 bg-success">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-sm-9 bg-warning">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>
亲自试一试 »

笔记:确保总和等于或小于 12(不需要使用所有 12 个可用列):

对于 33.3%/66.6% 的分割,您可以使用.col-sm-4.col-sm-8(对于 50%/50% 的分割,您可以使用.col-sm-6.col-sm-6):

.col-sm-4
.col-sm-8
.col-sm-6
.col-sm-6

示例

<!-- 33.3/66.6% split: -->
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-4 bg-success">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-sm-8 bg-warning">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>

<!-- 50%/50% split: -->
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6 bg-success">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-sm-6 bg-warning">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>
亲自试一试 »

自动布局列

在 Bootstrap 4 中,有一种简单的方法可以为所有设备创建等宽的列:只需删除其中的数字即可.col-sm-*并且只使用.col-sm指定数量的类山口元素。 Bootstrap 将识别有多少列,并且每列将获得相同的宽度。

如果屏幕尺寸是小于 576 像素,列将水平堆叠:

<!-- Two columns: 50% width on all screens, except for extra small (100% width) -->
<div class="row">
  <div class="col-sm">1 of 2</div>
  <div class="col-sm">2 of 2</div>
</div>

<!-- Four columns: 25% width on all screens, except for extra small (100% width)-->
<div class="row">
  <div class="col-sm">1 of 4</div>
  <div class="col-sm">2 of 4</div>
  <div class="col-sm">3 of 4</div>
  <div class="col-sm">4 of 4</div>
</div>
1 个(共 2 个)
2 共 2 个
1 个(共 4 个)
2 共 4 个
3 共 4 个
4 共 4 个
亲自试一试 »

下一章介绍如何为中型设备添加不同的分割百分比。