Grid and spacing

BS04. 排版系統 Grid system

為了便利使用者設計版面,bootstrap通常以12等分作為切割等寬欄位的基準,並且讓使用者得以利用class來指定他要怎麼切割這12個等寬欄位。

  • 首先要指定一個<div class="row">之後在其中再建立其他<div>

  • .col-sm-4其中的sm所指的是這個版面要給平板電腦用的,其他的代號包含xs for phones、md for desktops、and lg for larger desktops。

將一列的版面切割為4:4:4三塊。

將一列的版面切割為4:8兩個不等的區塊。

刻意在左方來作為留白。

若希望在grid排版上能夠左邊空出4,然後只留下右邊8,一來可以用上面那種辦法,先做一個空的.col-sm-4的<div>,再做一個.col-sm-8的<div>。但事實上,如果你始終不會用到左邊那區塊的話,可以用 來製作間隔

參考資料 http://getbootstrap.com/css/

標準寫法:使用offset

BS04.1 Grid system for RWD

See https://getbootstrap.com/docs/4.0/layout/grid/

Bootstrap在3.0與4.5版分別提供四到五個等級的「斷點」,為預設的不同瀏覽器大小,讓程式設計師可以用指派class,就設定好因應不同螢幕大小的排版。一共分為以下五階層。

https://getbootstrap.com/docs/4.0/layout/grid/

當程式碼如以下指定,代表我們希望這些元件在不同螢幕大小時有不一樣的表現

以上面的code而言,那螢幕夠大的時候看起來應該是如下圖,目前是照三個.col-md-4來排版。

若是螢幕太小的話,那就會變成按照.col-6來排版,那就是兩個col-6,所以中間那列的元件會排成兩欄如下。

<Practice> #1. 用grid system完成剩下的division

About glyphicon, take a look at http://www.w3schools.com/bootstrap/bootstrap_ref_comp_glyphs.asp

BS04.1 Layout:clearfix

https://getbootstrap.com/docs/4.0/utilities/clearfix/

主要是提供clear:both功能的class。

BS05. Spacing: Margin and Padding

See https://getbootstrap.com/docs/4.0/utilities/spacing/

Examples

https://getbootstrap.com/docs/4.0/utilities/spacing/

Where property is one of:

  • m - for classes that set margin

  • p - for classes that set padding

Where sides is one of:

  • t - for classes that set margin-top or padding-top

  • b - for classes that set margin-bottom or padding-bottom

  • l - for classes that set margin-left or padding-left

  • r - for classes that set margin-right or padding-right

  • x - for classes that set both *-left and *-right

  • y - for classes that set both *-top and *-bottom

  • blank - for classes that set a margin or padding on all 4 sides of the element

Where size is one of:

  • 0 - for classes that eliminate the margin or padding by setting it to 0

  • 1 - (by default) for classes that set the margin or padding to $spacer * .25

  • 2 - (by default) for classes that set the margin or padding to $spacer * .5

  • 3 - (by default) for classes that set the margin or padding to $spacer

  • 4 - (by default) for classes that set the margin or padding to $spacer * 1.5

  • 5 - (by default) for classes that set the margin or padding to $spacer * 3

  • auto - for classes that set the margin to auto

Last updated

Was this helpful?