📕
HTML
  • Course Materials
  • Tools for web basic
  • CodePen Examples
  • WEB1101
    • Rundown1101
    • Video Tutorials
    • Slides
  • HTML and CSS
    • HTML
    • CSS - basic
    • CSS - Object Decoration
    • CSS - Media Query
    • CSS-background-fixed
    • Positioning-sticky
    • Bootstrap
      • Grid and spacing
      • Useful Components
      • Component Cheatsheet
  • jquery
    • jquery basic
    • stick top
    • Progress-status bar
    • Parallax Scrolling
  • Design
    • Works by sketching
    • Movie Control
  • Case Studies
    • Great-cases
      • The Snow Fall
    • Case Studies by students
    • TW Digital 2019
    • Graphic Novel
    • Infographic
    • Ideas bottom-up by skills
    • News media outlet
  • Web1091
    • Student works 1091
    • Rundown1091
  • Appendix
    • The Color
    • File directory (Path)
    • Deployment
  • Data journalism
    • Data-Driven News Reports
Powered by GitBook
On this page
  • BS04. 排版系統 Grid system
  • 刻意在左方來作為留白。
  • BS04.1 Grid system for RWD
  • <Practice> #1. 用grid system完成剩下的division
  • <Practice> #2 Footer
  • BS04.1 Layout:clearfix
  • BS05. Spacing: Margin and Padding
  • Examples

Was this helpful?

  1. HTML and CSS
  2. Bootstrap

Grid and spacing

PreviousBootstrapNextUseful Components

Last updated 4 years ago

Was this helpful?

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>。但事實上,如果你始終不會用到左邊那區塊的話,可以用 來製作間隔

<div id="about" class="container-fluid">
    <div class="row">
        <div class="col-sm-3"></div>
        <div class="col-sm-9">
            <h2>About us</h2>
            <h4>hahaha</h4>
            <p>hehehe</p>
        </div>
    </div>
</div>

標準寫法:使用offset

<div id="intro" class="container-fluid">
    <div class="row">
        <div class="col-sm-9 offset-3">
            <h2>About us</h2></div>
    </div>
</div>

BS04.1 Grid system for RWD

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

// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px) { ... }

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) and (max-width: 767px) { ... }

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) and (max-width: 991px) { ... }

// Large devices (desktops, 992px and up)
@media (min-width: 992px) and (max-width: 1199px) { ... }

// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }

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

<!-- Stack the columns on mobile by making one full-width and the other half-width -->
<div class="row">
  <div class="col-12 col-md-8">.col-12 .col-md-8</div>
  <div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>

<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
<div class="row">
  <div class="col-6 col-md-4">.col-6 .col-md-4</div>
  <div class="col-6 col-md-4">.col-6 .col-md-4</div>
  <div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>

<!-- Columns are always 50% wide, on mobile and desktop -->
<div class="row">
  <div class="col-6">.col-6</div>
  <div class="col-6">.col-6</div>
</div>

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

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

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

<Practice> #2 Footer

<body id="myPage">
...
<footer class="container-fluid text-center">
    <a href="#myPage" title="back to top">
        <span class="glyphicon glyphicon-triangle-top"></span>
    </a>
    <p>Made By ji-lung</p>
</footer>
footer {
    background-color: #2d2d30;
    color: #f5f5f5;
    padding: 32px;
}

BS04.1 Layout:clearfix

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

<div class="bg-info clearfix">
  <button type="button" class="btn btn-secondary float-left">Example Button floated left</button>
  <button type="button" class="btn btn-secondary float-right">Example Button floated right</button>
</div>

BS05. Spacing: Margin and Padding

Examples

.mt-0 {
  margin-top: 0 !important;
}
.ml-1 {
  margin-left: ($spacer * .25) !important;
}
.px-2 {
  padding-left: ($spacer * .5) !important;
  padding-right: ($spacer * .5) !important;
}
.p-3 {
  padding: $spacer !important;
}

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

參考資料

See

About glyphicon, take a look at

See

http://getbootstrap.com/css/
https://getbootstrap.com/docs/4.0/layout/grid/
http://www.w3schools.com/bootstrap/bootstrap_ref_comp_glyphs.asp
https://getbootstrap.com/docs/4.0/utilities/clearfix/
https://getbootstrap.com/docs/4.0/utilities/spacing/
https://getbootstrap.com/docs/4.0/utilities/spacing/
https://getbootstrap.com/docs/4.0/layout/grid/