CSS-grid-system.txt 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. Grid system
  2. ===============================================================================
  3. .. lead::
  4. Bootstrap includes a responsive, mobile first fluid grid system that
  5. appropriately scales up to 12 columns as the device or viewport size
  6. increases. It includes predefined classes for easy layout options, as well
  7. as powerful mixins for generating more semantic layouts.
  8. .. ----------------------------------------------------------------------------
  9. Introduction
  10. ------------
  11. Grid systems are used for creating page layouts through a series of rows and
  12. columns that house your content. Here's how the Bootstrap grid system works:
  13. * Rows must be placed within a `.container` (fixed-width) or `.container-fluid`
  14. (full-width) for proper alignment and padding.
  15. * Use rows to create horizontal groups of columns.
  16. * Content should be placed within columns, and only columns may be immediate children of rows.
  17. * Predefined grid classes like `.row` and `.col-xs-4` are available for quickly
  18. making grid layouts. Less mixins can also be used for more semantic layouts.
  19. * Columns create gutters (gaps between column content) via padding. That
  20. padding is offset in rows for the first and last column via negative margin
  21. on `.row` s.
  22. * Grid columns are created by specifying the number of twelve available columns
  23. you wish to span. For example, three equal columns would use three `.col-xs-4`.
  24. Look to the examples for applying these principles to your code.
  25. Look to the examples for applying these principles to your code.
  26. Media queries
  27. -------------
  28. We use the following media queries in our Less files to create the key
  29. breakpoints in our grid system.
  30. .. code:: css
  31. :class: highlight
  32. /* Extra small devices (phones, less than 768px) */
  33. /* No media query since this is the default in Bootstrap */
  34. /* Small devices (tablets, 768px and up) */
  35. @media (min-width: @screen-sm-min) { ... }
  36. /* Medium devices (desktops, 992px and up) */
  37. @media (min-width: @screen-md-min) { ... }
  38. /* Large devices (large desktops, 1200px and up) */
  39. @media (min-width: @screen-lg-min) { ... }
  40. We occasionally expand on these media queries to include a max-width to limit
  41. CSS to a narrower set of devices.
  42. .. code:: css
  43. :class: highlight
  44. @media (max-width: @screen-xs-max) { ... }
  45. @media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... }
  46. @media (min-width: @screen-md-min) and (max-width: @screen-md-max) { ... }
  47. @media (min-width: @screen-lg-min) { ... }
  48. Grid options
  49. ------------
  50. See how aspects of the Bootstrap grid system work across multiple devices with
  51. a handy table.
  52. .. table::
  53. :class: table table-bordered table-striped
  54. +---------------------+---------------------+------------------+-------------------+--------------------+
  55. | | Extra small devices | Small devices | Medium devices | Large devices |
  56. | | Phones (<768px) | Tablets (≥768px) | Desktops (≥992px) | Desktops (≥1200px) |
  57. +=====================+=====================+==================+===================+====================+
  58. | **Grid Behavior** | Horizontal at all | Collapsed to start, horizontal above breakpoints |
  59. | | times | |
  60. +---------------------+---------------------+------------------+-------------------+--------------------+
  61. | **Container Width** | None (auto) | 750px | 970px | 1170px |
  62. +---------------------+---------------------+------------------+-------------------+--------------------+
  63. | **Class Predix** | `col-xs-` | `col-sd-` | `col-md-` | `col-lg-` |
  64. +---------------------+---------------------+------------------+-------------------+--------------------+
  65. | **# Columns** | 12 |
  66. +---------------------+---------------------+------------------+-------------------+--------------------+
  67. | **Column Width** | :text-muted:`Auto` | 60px | 78px | 95px |
  68. +---------------------+---------------------+------------------+-------------------+--------------------+
  69. | **Gutter width** | 30px (15px on each side of a column) |
  70. +---------------------+---------------------+------------------+-------------------+--------------------+
  71. | **Netsable** | Yes |
  72. +---------------------+---------------------+------------------+-------------------+--------------------+
  73. | **Offsets** | Yes |
  74. +---------------------+---------------------+------------------+-------------------+--------------------+
  75. | **Column Ordering** | Yes |
  76. +---------------------+---------------------+------------------+-------------------+--------------------+
  77. Grid classes apply to devices with screen widths greater than or equal to the
  78. breakpoint sizes, and override grid classes targeted at smaller
  79. devices. Therefore, applying any `.col-md-` class to an element will not only
  80. affect its styling on medium devices but also on large devices if a `.col-lg-`
  81. class is not present.
  82. Example: Stacked-to-horizontal
  83. ------------------------------
  84. Using a single set of `.col-md-*` grid classes, you can create a basic grid
  85. system that starts out stacked on mobile devices and tablet devices (the extra
  86. small to small range) before becoming horizontal on desktop (medium)
  87. devices. Place grid columns in any `.row`.
  88. .. row:: show-grid
  89. .. column:: .col-md-1
  90. .. column:: .col-md-1
  91. .. column:: .col-md-1
  92. .. column:: .col-md-1
  93. .. column:: .col-md-1
  94. .. column:: .col-md-1
  95. .. column:: .col-md-1
  96. .. column:: .col-md-1
  97. .. column:: .col-md-1
  98. .. column:: .col-md-1
  99. .. column:: .col-md-1
  100. .. column:: .col-md-1
  101. .. row:: show-grid
  102. .. column:: .col-md-8
  103. :width: 8
  104. .. column:: .col-md-4
  105. :width: 4
  106. .. row:: show-grid
  107. .. column:: .col-md-4
  108. :width: 4
  109. .. column:: .col-md-4
  110. :width: 4
  111. .. column:: .col-md-4
  112. :width: 4
  113. .. row:: show-grid
  114. .. column:: .col-md-6
  115. :width: 6
  116. .. column:: .col-md-6
  117. :width: 6
  118. Offsetting columns
  119. ------------------
  120. Move columns to the right using `.col-md-offset-*` classes. These classes
  121. increase the left margin of a column by * columns. For example,
  122. `.col-md-offset-4` moves `.col-md-4` over four columns.
  123. .. row:: show-grid
  124. .. column:: .col-md-4
  125. :width: 4
  126. .. column:: .col-md-4
  127. :width: 4
  128. :offset: 4
  129. .. row:: show-grid
  130. .. column:: .col-md-3
  131. :width: 3
  132. :offset: 3
  133. .. column:: .col-md-3
  134. :width: 3
  135. :offset: 3
  136. .. row:: show-grid
  137. .. column:: .col-md-6
  138. :width: 6
  139. :offset: 3
  140. Nesting columns
  141. ---------------
  142. To nest your content with the default grid, add a new `.row` and set of
  143. `.col-md-*` columns within an existing `.col-md-*` column. Nested rows should
  144. include a set of columns that add up to 12 or less.
  145. .. row:: show-grid
  146. .. column:: Level 1: .col-md-9
  147. :width: 9
  148. .. row:: show-grid
  149. .. column:: Level 2: .col-md-6
  150. :width: 6
  151. .. column:: Level 2: .col-md-6
  152. :width: 6
  153. Column ordering
  154. ---------------
  155. Easily change the order of our built-in grid columns with .col-md-push-* and
  156. .col-md-pull-* modifier classes.
  157. .. row:: show-grid
  158. .. column:: .col-md-9 . col-push-3
  159. :width: 9
  160. :push: 3
  161. .. column:: .col-md-3 . col-pull-9
  162. :width: 3
  163. :pull: 9
  164. .. code::
  165. :class: highlight
  166. .. column:: .col-md-9 . col-push-3
  167. :width: 9
  168. :push: 3
  169. .. column:: .col-md-3 . col-pull-9
  170. :width: 3
  171. :pull: 9