Bootstrap 5 網格 大螢幕
大螢幕網格示例
超小號 | 小 | 中 | 大 | 特大尺寸 | XXL | |
---|---|---|---|---|---|---|
類字首 | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
.col-xxl- |
螢幕寬度 | <576px | >=576px | >=768px | >=992px | >=1200px | >=1400px |
在上一個章節中,我們展示了一個具有針對小尺寸和大尺寸裝置的網格示例。我們使用了兩個 div(列),並在小尺寸裝置上將它們設定為 25%/75% 的比例,在尺寸裝置上設定為 50%/50% 的比例。
<div class="col-sm-3 col-md-6">....</div>
<div class="col-sm-9 col-md-6">....</div>
但在大尺寸裝置上,33%/66% 的比例可能更好。
大螢幕裝置定義為螢幕寬度從992畫素到1199畫素。
對於大螢幕裝置,我們將使用.col-lg-*
類。
<div class="col-sm-3 col-md-6 col-lg-4">....</div>
<div class="col-sm-9 col-md-6 col-lg-8">....</div>
現在 Bootstrap 將會說“在小尺寸裝置上,檢視帶有-sm-的類並使用它們。在中等尺寸裝置上,檢視帶有-md-的類並使用它們。在大尺寸裝置上,檢視帶有-lg-的類並使用它們。”
下面的示例將在小螢幕裝置上產生25%/75%的分割,在中等螢幕裝置上產生50%/50%的分割,在大、超大和XXL螢幕裝置上產生33%/66%的分割。在超小螢幕裝置上,它們將自動堆疊(100%)。
.col-sm-3 .col-md-6 .col-lg-4
.col-sm-9 .col-md-6 .col-lg-8
示例
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 col-md-6 col-lg-8">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
自己動手試一試 »
注意: 確保總和為 12 或更少(不要求使用所有 12 個可用列)。
僅使用大尺寸
在下面的示例中,我們只指定了.col-lg-6
類(不帶.col-md-*
和/或.col-sm-*
)。這意味著大、超大和XXL螢幕裝置將各佔50%。然而,對於中、小和超小螢幕裝置,它們將垂直堆疊(100%寬度)。
示例
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<p>Lorem ipsum...</p>
</div>
<div class="col-lg-6">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
自己動手試一試 »
自動佈局列
在 Bootstrap 5 中,有一種簡單的方法可以為所有裝置建立等寬的列:只需從.col-lg-*
中刪除數字,並在指定的.col
元素數量上僅使用.col-lg
類。Bootstrap 將識別出有多少列,並且每一列將獲得相同的寬度。
如果螢幕尺寸小於992px,列將水平堆疊。
<!-- 兩列:大螢幕及以上裝置佔50%寬度 -->
<div class="row">
<div class="col-lg">1 of 2</div>
<div class="col-lg">2 of 2</div>
</div>
<!-- 四列:大螢幕及以上裝置佔25%寬度 -->
<div class="row">
<div class="col-lg">1 of 4</div>
<div class="col-lg">2 of 4</div>
<div class="col-lg">3 of 4</div>
<div class="col-lg">4 of 4</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4