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 4 网格 超小型


超小型网格示例

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

假设我们有一个简单的布局,包含两列。我们希望这两列在所有设备上分别占 25% 和 75% 的宽度。

我们将向这两列添加以下类

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

以下示例将在所有设备(超小型、小型、中等、大型和超大型)上实现 25% / 75% 的分割。

col-3
col-9

示例

<div class="container-fluid">
  <div class="row">
    <div class="col-3 bg-success">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-9 bg-warning">
      <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-success">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-8 bg-warning">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>

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

自动布局列

在 Bootstrap 4 中,有一种简单的方法可以为所有设备创建等宽列:只需从 .col-* 中删除数字,并在指定数量的 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.