Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 5 网格 小


小型网格示例

  特小 特大 超大
类前缀 .col- .col-sm- .col-md- .col-lg- .col-xl- .col-xxl-
屏幕宽度 <576px >=576px >=768px >=992px >=1200px >=1400px

假设我们有一个简单的布局,包含两列。我们希望这两列在小型设备上按 25%/75% 的比例分割。

小型设备是指屏幕宽度介于 **576 像素到 767 像素**之间的设备。

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

我们将在两列中添加以下类

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

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

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

示例

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3 bg-primary">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-sm-9 bg-dark">
      <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% 分割:-->
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-4 bg-primary">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-sm-8 bg-dark">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>

<!-- 50%/50% 分割:-->
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6 bg-primary">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-sm-6 bg-dark">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>
动手尝试 »


自动布局列

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

如果屏幕尺寸 **小于 576px**,列将水平堆叠

<!-- 两列:所有屏幕上为 50% 宽度,特小屏幕除外(100% 宽度)-->
<div class="row">
  <div class="col-sm">1 of 2</div>
  <div class="col-sm">2 of 2</div>
</div>

<!-- 四列:所有屏幕上为 25% 宽度,特小屏幕除外(100% 宽度)-->
<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 of 2
2 of 2

1 of 4
2 of 4
3 of 4
4 of 4
动手尝试 »

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


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.