bootstrap的container樣式 Grid Options
一、bootstrap是以.container包裹原始碼來產生特效
<html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body> <div class="container"> <div class="row"> <h2>Form control: input</h2> <p>The form below contains two input elements; one of type text and one of type password:</p> <form role="form"> <div class="form-group"> <div class="input-group"> <input type="text" name="your-name" value="" size="40" id="name" class="form-control" placeholder="您的稱呼"> <span class="input-group-addon" id="basic-addon1">先生</span> </div> </div> </form> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> </body> </html>
.container為fixed layout(固定外圍寬度)
.container-fluid為全屏
一個例子當該div為6column(class="col-lg-6")時;
瀏覽器寬度小於1200px但大於600px,則div樣式不變,div占container的一半,
當瀏覽器寬度小於600px時,則column為6的div則開始主動占container的全部了。
Grid Options
The following table summarizes how the Bootstrap grid system works across multiple devices:
臨界值 | Extra small devices Phones (<388px) |
Small devices Tablets (>=768px) |
Medium devices Desktops (>=992px) |
Large devices Desktops (>=1200px) |
---|---|---|---|---|
Grid behaviour | Horizontal at all times | Collapsed to start, horizontal above breakpoints | Collapsed to start, horizontal above breakpoints | Collapsed to start, horizontal above breakpoints |
Container width | None (auto) | 750px | 970px | 1170px |
Class prefix | .col-xs- | .col-sm- | .col-md- | .col-lg- |
Number of columns | 12 | 12 | 12 | 12 |
Column width | Auto | 62px~81px | 81px~95px | 95px |
Gutter width | 30px (15px on each side of a column) | 30px (15px on each side of a column) | 30px (15px on each side of a column) | 30px (15px on each side of a column) |
Nestable | Yes | Yes | Yes | Yes |
Offsets | Yes | Yes | Yes | Yes |
Column ordering | Yes | Yes | Yes | Yes |
P.S. auto代表自動縮放、排列。
注意container底下一定要配合row,否則RWD效果可能會出不來
<div class="container"> <div class="row"> </div> <div class="row"> </div> <div class="row"> </div> </div>
最後提供container與row樣式請參考
.container ,.container-fluid { padding-right: 15px; padding-left: 15px; margin-right: auto; margin-left: auto; }
.row { margin-right: -15px; margin-left: -15px; }
参考網址: