Components and options for laying out your Bootstrap project, including wrapping containers, a powerful grid system, a flexible media object, and responsive utility classes. — Bootstrap
<div class="container"> <!-- Content here --> </div>
.container-fluid
不考慮螢幕寬度,始終將寬度設定為auto,當縮放瀏覽器時,保持全屏大小(100%的寬度)。
1 2 3
<div class="container-fluid"> ... </div>
.container-{breakpoint}
透過Bootstrap寫好的 Media Query 調整頁面
如: .container-sm
1 2 3 4
<div class="container-sm">100% wide until small breakpoint</div> <div class="container-md">100% wide until medium breakpoint</div> <div class="container-lg">100% wide until large breakpoint</div> <div class="container-xl">100% wide until extra large breakpoint</div>
👇 .container-{breakpoint} 細節
介紹完Container後,緊接著介紹Bootstrap的欄位配置 — Grid System 😉
📝 Grid System
Use our powerful mobile-first flexbox grid to build layouts of all shapes and sizes thanks to a twelve column system, five default responsive tiers, Sass variables and mixins, and dozens of predefined classes. — Bootstrap
💡Hint: Bootstrap 以 Grid System 規範網頁的版面配置 (列 - 欄) ,而1列在Bootstrap中被預設劃分為12欄。
⭐ Setting Row & Column
👇 不設定的col-size情況下,3欄均分12個欄位大小 (3 X 4)
1 2 3 4 5 6 7 8 9 10 11 12 13
<div class="container"> <div class="row"> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> </div> </div>
<div class="col-12 col-md-9"> <h1>title</h1> <p>List groups are a flexible and powerful component for displaying a series of content. Modify and extend them to support just about any content within.</p> <div class="row item-group"> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=8"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=2"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=4"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=5"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=38"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=32"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=34"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=35"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> </div> </div>
<div class="container"> <div class="row"> <div class="col-12 col-md-3"> <div class="list-group"> <a href="#" class="list-group-item list-group-item-action active" aria-current="true">The current link item</a> <a href="#" class="list-group-item list-group-item-action">A second link item</a> <a href="#" class="list-group-item list-group-item-action">A third link item</a> <a href="#" class="list-group-item list-group-item-action">A fourth link item</a> <a href="#" class="list-group-item list-group-item-action disabled" tabindex="-1" aria-disabled="true">A disabled link item</a> </div> </div> <div class="col-12 col-md-9"> <h1>title</h1> <p>List groups are a flexible and powerful component for displaying a series of content. Modify and extend them to support just about any content within.</p> <div class="row item-group"> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=8"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=2"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=4"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=5"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=38"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=32"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=34"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> <div class="col-12 col-md-3"> <div class="item"> <img class="img-fluid" src="https://picsum.photos/300/200?random=35"> <h3>title</h3> <p>List groups are a flexible and powerful component for displaying</p> </div> </div> </div> </div> </div> </div>
定義:
The CSS box model describes the rectangular boxes that are generated for elements in the document tree and laid out according to the visual formatting model.
簡單來說平常寫的<p>lorem...</p>,就可以看做是一個Box,而Box Model則規範Box在瀏覽器上的長相。
在Chrome裡滑鼠右鍵 檢查 (F12),可以在右方(Styles)看到如下畫面
Margin: box 的外部距離區域
Border: box 的邊界
Padding: box content 外的填充區域
Content: Content實際的寬 X 高
💡Hint: Chrome提供的檢查功能可以提升我們在網頁設計上的效率,比如:你寫出的網頁在不同尺寸的裝置上顯示的版面差異,方便我們做進一步的RWD (Responsive Web Design) 規劃。