Bootstrap 网格 - 大型设备
Bootstrap 网格示例:大型设备
超小屏 | 小 | 中 | 大 | |
---|---|---|---|---|
类前缀 | .col-xs |
.col-sm |
.col-md |
.col-lg |
屏幕宽度 | <768px | >=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% 的比例可能更好。
提示: 大型设备定义为屏幕宽度为1200 像素及以上。
对于大型设备,我们将使用 .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 现在会说“在小尺寸设备上,查看包含 -sm- 的类并使用它们。在中等尺寸设备上,查看包含 -md- 的类并使用它们。在大尺寸设备上,查看包含 -lg- 的类并使用它们”。
以下示例在小尺寸设备上将实现 25%/75% 的分割,在中等尺寸设备上实现 50%/50% 的分割,在大尺寸设备上实现 33%/66% 的分割
示例
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4" style="background-color:yellow;">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 col-md-6 col-lg-8" style="background-color:pink;">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
自己动手试一试 »
注意:确保总和始终为 12。
仅使用大尺寸
在下面的示例中,我们只指定了 .col-lg-6
类(没有 .col-md-*
和/或 .col-sm-*
)。这意味着大型设备将实现 50%/50% 的分割。但是,对于中等和小型设备,它将垂直堆叠(100% 宽度)
示例
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-lg-6" style="background-color:yellow;">
<p>Lorem ipsum...</p>
</div>
<div class="col-lg-6" style="background-color:pink;">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
自己动手试一试 »