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 超小尺寸网格


超小尺寸网格示例

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

假设我们有一个简单的两列布局。我们希望这两列在所有设备上以 25%/75% 的比例分割。

我们将为我们的两列添加以下类

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

以下示例将在所有设备(超小尺寸、小尺寸、中尺寸、大尺寸、超大尺寸和 XXL 尺寸)上产生 25%/75% 的分割。

col-3
col-9

示例

<div class="container-fluid">
  <div class="row">
    <div class="col-3 bg-primary">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-9 bg-dark">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>
尝试一下 »

注意:请确保总和加起来不超过 12(不需要使用所有 12 个可用的列)

对于 33.3%/66.6% 的分割,您将使用 .col-4.col-8(对于 50%/50% 的分割,您将使用 .col-6.col-6

col-4
col-8

col-6
col-6

示例

<!-- 33.3%/66.6% 分割 -->
<div class="container-fluid">
  <div class="row">
    <div class="col-4 bg-primary">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-8 bg-dark">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>

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


自动布局列

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

<!-- 两列:50% 宽度-->
<div class="row">
  <div class="col">1 of 2</div>
  <div class="col">2 of 2</div>
</div>

<!-- 四列:25% 宽度-->
<div class="row">
  <div class="col">1 of 4</div>
  <div class="col">2 of 4</div>
  <div class="col">3 of 4</div>
  <div class="col">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.