• Columns build on the grid’s flexbox architecture. Flexbox means we have options for changing individual columns and modifying groups of columns at the row level. You choose how columns grow, shrink, or otherwise change.

  • When building grid layouts, all content goes in columns. The hierarchy of Bootstrap’s grid goes from to row to column to your content. On rare occasions, you may combine content and column, but be aware there can be unintended consequences.

  • Bootstrap includes predefined classes for creating fast, responsive layouts. With six breakpoints and a dozen columns at each grid tier, we have dozens of classes already built for you to create your desired layouts. This can be disabled via Sass if you wish.

Use flexbox alignment utilities to vertically and horizontally align columns.

Columns - 图2

  1. <div class="row">
  2. <div class="col align-self-start">
  3. One of three columns
  4. </div>
  5. <div class="col align-self-center">
  6. One of three columns
  7. </div>
  8. <div class="col align-self-end">
  9. One of three columns
  10. </div>
  11. </div>
  12. </div>

Horizontal alignment

  1. <div class="container">
  2. <div class="row justify-content-start">
  3. <div class="col-4">
  4. One of two columns
  5. </div>
  6. <div class="col-4">
  7. One of two columns
  8. </div>
  9. </div>
  10. <div class="row justify-content-center">
  11. <div class="col-4">
  12. One of two columns
  13. </div>
  14. <div class="col-4">
  15. One of two columns
  16. </div>
  17. </div>
  18. <div class="row justify-content-end">
  19. <div class="col-4">
  20. One of two columns
  21. </div>
  22. <div class="col-4">
  23. One of two columns
  24. </div>
  25. <div class="row justify-content-around">
  26. <div class="col-4">
  27. One of two columns
  28. </div>
  29. <div class="col-4">
  30. One of two columns
  31. </div>
  32. </div>
  33. <div class="row justify-content-between">
  34. <div class="col-4">
  35. One of two columns
  36. </div>
  37. <div class="col-4">
  38. One of two columns
  39. </div>
  40. <div class="row justify-content-evenly">
  41. <div class="col-4">
  42. One of two columns
  43. </div>
  44. <div class="col-4">
  45. One of two columns
  46. </div>
  47. </div>
  48. </div>

If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-9">.col-9</div>
  4. <div class="col-4">.col-4<br>Since 9 + 4 = 13 &gt; 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.</div>
  5. <div class="col-6">.col-6<br>Subsequent columns continue along the new line.</div>
  6. </div>
  7. </div>

Column breaks

Breaking columns to a new line in flexbox requires a small hack: add an element with width: 100% wherever you want to wrap your columns to a new line. Normally this is accomplished with multiple .rows, but not every implementation method can account for this.

Columns - 图5

You may also apply this break at specific breakpoints with our .

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
  4. <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
  5. <!-- Force next columns to break to new line at md breakpoint and up -->
  6. <div class="w-100 d-none d-md-block"></div>
  7. <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
  8. <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
  9. </div>
  10. </div>

Use .order- classes for controlling the visual order of your content. These classes are responsive, so you can set the order by breakpoint (e.g., .order-1.order-md-2). Includes support for 1 through 5 across all six grid tiers.

Columns - 图7

  1. <div class="container">
  2. <div class="row">
  3. <div class="col">
  4. First in DOM, no order applied
  5. </div>
  6. Second in DOM, with a larger order
  7. </div>
  8. <div class="col order-1">
  9. Third in DOM, with an order of 1
  10. </div>
  11. </div>
  12. </div>

There are also responsive .order-first and .order-last classes that change the order of an element by applying order: -1 and , respectively. These classes can also be intermixed with the numbered .order-* classes as needed.

  1. <div class="container">
  2. <div class="row">
  3. <div class="col order-last">
  4. First in DOM, ordered last
  5. </div>
  6. <div class="col">
  7. Second in DOM, unordered
  8. </div>
  9. <div class="col order-first">
  10. Third in DOM, ordered first
  11. </div>
  12. </div>
  13. </div>

Offsetting columns

Offset classes

Move columns to the right using .offset-md-* classes. These classes increase the left margin of a column by * columns. For example, .offset-md-4 moves .col-md-4 over four columns.

Columns - 图9

In addition to column clearing at responsive breakpoints, you may need to reset offsets. See this in action in the grid example.

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-sm-5 col-md-6">.col-sm-5 .col-md-6</div>
  4. <div class="col-sm-5 offset-sm-2 col-md-6 offset-md-0">.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0</div>
  5. </div>
  6. <div class="row">
  7. <div class="col-sm-6 col-md-5 col-lg-6">.col-sm-6 .col-md-5 .col-lg-6</div>
  8. <div class="col-sm-6 col-md-5 offset-md-2 col-lg-6 offset-lg-0">.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0</div>
  9. </div>
  10. </div>

Margin utilities

With the move to flexbox in v4, you can use margin utilities like .me-auto to force sibling columns away from one another.

Columns - 图11

  1. <div class="container">
  2. <div class="row">
  3. <div class="col-md-4">.col-md-4</div>
  4. <div class="col-md-4 ms-auto">.col-md-4 .ms-auto</div>
  5. </div>
  6. <div class="row">
  7. <div class="col-md-3 ms-md-auto">.col-md-3 .ms-md-auto</div>
  8. <div class="col-md-3 ms-md-auto">.col-md-3 .ms-md-auto</div>
  9. </div>
  10. <div class="row">
  11. <div class="col-auto me-auto">.col-auto .me-auto</div>
  12. <div class="col-auto">.col-auto</div>
  13. </div>
  14. </div>

The .col-* classes can also be used outside a .row to give an element a specific width. Whenever column classes are used as non direct children of a row, the paddings are omitted.

  1. <div class="col-3 bg-light p-3 border">
  2. .col-3: width of 25%
  3. </div>
  4. <div class="col-sm-9 bg-light p-3 border">
  5. .col-sm-9: width of 75% above sm breakpoint
  6. </div>

Columns - 图13