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

在上一章中,我们介绍了一个包含中小型设备类的网格示例。我们使用了两个 div(列),并在小型设备上将其分配为 25%/75%,在中型设备上将其分配为 50%/50%:

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

但在大型设备上,33%/66% 分割的设计可能会更好。

大型设备被定义为屏幕宽度为992 像素至 1199 像素

对于大型设备,我们将使用.col-lg-*课程:

<div class="col-sm-3 col-md-6 col-lg-4">....</div>
<div class="col-sm-9 col-md-6 col-lg-8">....</div>

现在 Bootstrap 会显示"at the small size, look at classes with -sm- in them and use those. At the medium size, look at classes with -md- in them and use those. At the large size, look at classes with the word -lg- in them and use those"。

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

.col-sm-3 .col-md-6 .col-lg-4
.col-sm-9 .col-md-6 .col-lg-8

示例

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3 col-md-6 col-lg-4">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-sm-9 col-md-6 col-lg-8">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>
亲自试一试 »

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


仅使用大

在下面的例子中,我们只指定.col-lg-6类(无.col-md-*和/或.col-sm-*)。这意味着大型和超大型设备将分成 50%/50%。但是,对于中型、小型和超小型设备,它将垂直堆叠(100% 宽度):

示例

<div class="container-fluid">
  <div class="row">
    <div class="col-lg-6">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-lg-6">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>
亲自试一试 »

自动布局列

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

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

<!-- Two columns: 50% width on large and up-->
<div class="row">
  <div class="col-lg">1 of 2</div>
  <div class="col-lg">2 of 2</div>
</div>

<!-- Four columns: 25% width on large and up -->
<div class="row">
  <div class="col-lg">1 of 4</div>
  <div class="col-lg">2 of 4</div>
  <div class="col-lg">3 of 4</div>
  <div class="col-lg">4 of 4</div>
</div>
1 个(共 2 个)
2 共 2 个
1 个(共 4 个)
2 共 4 个
3 共 4 个
4 共 4 个
亲自试一试 »