Bootstrap 5 Grid: Medium Device

Zhongxing shebei wangge shili

XSmall Small Medium Large Extra Large XXL
lei qianzhou .col- .col-sm- .col-md- .col-lg- .col-xl- .col-xxl-
pingmu kuandu <576px >=576px >=768px >=992px >=1200px >=1400px

Zai qianyiban zhong, women zhanshi le yi ge wangge shili, zhonghuan yongyu xiaoxing shebei de lei. Women shiyong le liang ge div (lie), bing gei ta men 25% / 75% de chiafen:

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

Dan zai zhongxing shebei shang, 50% / 50% chiafen sheji keshi hui geng hao.

Zhongxing shebei bei定义为 pingmu kuanduCong 768 xiangsu dizhi 991 xiangsu

Duiyu zhongxing shebei, women jiang shiyong .col-md-* lei:

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

zai xiaoxing shebei shang, qing shiyong baohan -sm- de lei. Zai zhongxing shebei shang, qing shiyong baohan -md- de lei.

Hanyan zai xiaoxing shebei shang xiangda 25% / 75% chiafen, zai zhongxing (yiqi da, chada he teda) shebei shang 50% / 50% chiafen. Zai chaoxiao shebei shang, ta zidingji taijie (100%):

Example

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3 col-md-6">
      <p>The World Wide Fund for Nature (WWF), founded on April 29, 1961, has a giant panda as its logo...</p>
    </div>
    <div class="col-sm-9 col-md-6">
      <p>In 1980, WWF officially came to China, invited by the Chinese government to carry out the protection work of giant pandas and their habitats...</p>
    </div>
  </div>
</div>

Try It Yourself

Note:Make sure the total is equal to or less than 12 (you do not need to use all 12 available columns):

Only use Medium

In the following example, we only specify .col-md-6 Class (without .col-sm-*). This means that medium, large, extra-large, and XXL devices will split 50% / 50% - because this class will expand. However, for small and extra-small devices, they will be vertically stacked (100% width):

Example

<div class="row">
  <div class="col-md-6">
    <p>The World Wide Fund for Nature (WWF), founded on April 29, 1961, has a giant panda as its logo...</p>
  </div>
  <div class="col-md-6">
    <p>In 1980, WWF officially came to China, invited by the Chinese government to carry out the protection work of giant pandas and their habitats...</p>
  </div>
</div>

Try It Yourself

Automatic Layout Columns

In Bootstrap 5, there is a simple way to create equal-width columns for all devices: just from .col-md-* Remove the numbers and use only on the col element .col-md Class. Bootstrap will recognize how many columns there are, and each column will get the same width.

If the screen sizeLess than 768px, columns will be stacked horizontally:

<!-- Two columns: 50% width on medium and larger devices -->
<div class="row">
  <div class="col-md">1 of 2</div>
  <div class="col-md">2 of 2</div>
</div>
<!-- Four columns: 25% width on medium and larger devices -->
<div class="row">
  <div class="col-md">1 of 4</div>
  <div class="col-md">2 of 4</div>
  <div class="col-md">3 of 4</div>
  <div class="col-md">4 of 4</div>
</div>

Try It Yourself

The next chapter will show how to add different split percentages for large devices.