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 网格 - 堆叠到水平


Bootstrap 网格示例:堆叠到水平

我们将创建一个基本的网格系统,该系统在超小型设备上开始堆叠,然后在较大的设备上变为水平。

以下示例显示了一个简单的“堆叠到水平”的两列布局,这意味着它将在所有屏幕上产生 50%/50% 的分割,除了超小型屏幕,它将自动堆叠(100%)

col-sm-6
col-sm-6

示例:堆叠到水平

<div class="container">
  <h1>Hello World!</h1>
  <div class="row">
    <div class="col-sm-6" style="background-color:yellow;">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-sm-6" style="background-color:pink;">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>
亲自尝试 »

提示:.col-sm-* 类中的数字表示 div 应该跨越多少列(共 12 列)。因此,.col-sm-1 跨越 1 列,.col-sm-4 跨越 4 列,.col-sm-6 跨越 6 列,等等。

注意:确保总和始终加起来为 12!

提示:你可以将任何固定宽度布局转换为全宽布局,方法是将 .container 类更改为 .container-fluid

示例:流体容器

<div class="container-fluid">
  <h1>Hello World!</h1>
  <div class="row">
    <div class="col-sm-6" style="background-color:yellow;">
      <p>Lorem ipsum...</p>
    </div>
    <div class="col-sm-6" style="background-color:pink;">
      <p>Sed ut perspiciatis...</p>
    </div>
  </div>
</div>
亲自尝试 »

×

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.