Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
---
2
layout: docs
3
title: Grid system
4
description: Use our powerful mobile-first flexbox grid to build layouts of all shapes and sizes thanks to a twelve column system, five default responsive tiers, Sass variables and mixins, and dozens of predefined classes.
5
group: layout
6
toc: true
7
---
8
 
9
## How it works
10
 
11
Bootstrap's grid system uses a series of containers, rows, and columns to layout and align content. It's built with [flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox) and is fully responsive. Below is an example and an in-depth look at how the grid comes together.
12
 
13
**New to or unfamiliar with flexbox?** [Read this CSS Tricks flexbox guide](https://css-tricks.com/snippets/css/a-guide-to-flexbox/#flexbox-background) for background, terminology, guidelines, and code snippets.
14
 
15
{{< example class="bd-example-row" >}}
16
<div class="container">
17
  <div class="row">
18
    <div class="col-sm">
19
      One of three columns
20
    </div>
21
    <div class="col-sm">
22
      One of three columns
23
    </div>
24
    <div class="col-sm">
25
      One of three columns
26
    </div>
27
  </div>
28
</div>
29
{{< /example >}}
30
 
31
The above example creates three equal-width columns on small, medium, large, and extra large devices using our predefined grid classes. Those columns are centered in the page with the parent `.container`.
32
 
33
Breaking it down, here's how it works:
34
 
35
- Containers provide a means to center and horizontally pad your site's contents. Use `.container` for a responsive pixel width or `.container-fluid` for `width: 100%` across all viewport and device sizes.
36
- Rows are wrappers for columns. Each column has horizontal `padding` (called a gutter) for controlling the space between them. This `padding` is then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side.
37
- In a grid layout, content must be placed within columns and only columns may be immediate children of rows.
38
- Thanks to flexbox, grid columns without a specified `width` will automatically layout as equal width columns. For example, four instances of `.col-sm` will each automatically be 25% wide from the small breakpoint and up. See the [auto-layout columns](#auto-layout-columns) section for more examples.
39
- Column classes indicate the number of columns you'd like to use out of the possible 12 per row. So, if you want three equal-width columns across, you can use `.col-4`.
40
- Column `width`s are set in percentages, so they're always fluid and sized relative to their parent element.
41
- Columns have horizontal `padding` to create the gutters between individual columns, however, you can remove the `margin` from rows and `padding` from columns with `.no-gutters` on the `.row`.
42
- To make the grid responsive, there are five grid breakpoints, one for each [responsive breakpoint]({{< docsref "/layout/overview#responsive-breakpoints" >}}): all breakpoints (extra small), small, medium, large, and extra large.
43
- Grid breakpoints are based on minimum width media queries, meaning **they apply to that one breakpoint and all those above it** (e.g., `.col-sm-4` applies to small, medium, large, and extra large devices, but not the first `xs` breakpoint).
44
- You can use predefined grid classes (like `.col-4`) or [Sass mixins](#sass-mixins) for more semantic markup.
45
 
46
Be aware of the limitations and [bugs around flexbox](https://github.com/philipwalton/flexbugs), like the [inability to use some HTML elements as flex containers](https://github.com/philipwalton/flexbugs#flexbug-9).
47
 
48
## Grid options
49
 
50
While Bootstrap uses `em`s or `rem`s for defining most sizes, `px`s are used for grid breakpoints and container widths. This is because the viewport width is in pixels and does not change with the [font size](https://drafts.csswg.org/mediaqueries-3/#units).
51
 
52
See how aspects of the Bootstrap grid system work across multiple devices with a handy table.
53
 
54
<table class="table table-bordered table-striped">
55
  <thead>
56
    <tr>
57
      <th></th>
58
      <th class="text-center">
59
        Extra small<br>
60
        <small>&lt;576px</small>
61
      </th>
62
      <th class="text-center">
63
        Small<br>
64
        <small>&ge;576px</small>
65
      </th>
66
      <th class="text-center">
67
        Medium<br>
68
        <small>&ge;768px</small>
69
      </th>
70
      <th class="text-center">
71
        Large<br>
72
        <small>&ge;992px</small>
73
      </th>
74
      <th class="text-center">
75
        Extra large<br>
76
        <small>&ge;1200px</small>
77
      </th>
78
    </tr>
79
  </thead>
80
  <tbody>
81
    <tr>
82
      <th class="text-nowrap" scope="row">Max container width</th>
83
      <td>None (auto)</td>
84
      <td>540px</td>
85
      <td>720px</td>
86
      <td>960px</td>
87
      <td>1140px</td>
88
    </tr>
89
    <tr>
90
      <th class="text-nowrap" scope="row">Class prefix</th>
91
      <td><code>.col-</code></td>
92
      <td><code>.col-sm-</code></td>
93
      <td><code>.col-md-</code></td>
94
      <td><code>.col-lg-</code></td>
95
      <td><code>.col-xl-</code></td>
96
    </tr>
97
    <tr>
98
      <th class="text-nowrap" scope="row"># of columns</th>
99
      <td colspan="5">12</td>
100
    </tr>
101
    <tr>
102
      <th class="text-nowrap" scope="row">Gutter width</th>
103
      <td colspan="5">30px (15px on each side of a column)</td>
104
    </tr>
105
    <tr>
106
      <th class="text-nowrap" scope="row">Nestable</th>
107
      <td colspan="5">Yes</td>
108
    </tr>
109
    <tr>
110
      <th class="text-nowrap" scope="row">Column ordering</th>
111
      <td colspan="5">Yes</td>
112
    </tr>
113
  </tbody>
114
</table>
115
 
116
## Auto-layout columns
117
 
118
Utilize breakpoint-specific column classes for easy column sizing without an explicit numbered class like `.col-sm-6`.
119
 
120
### Equal-width
121
 
122
For example, here are two grid layouts that apply to every device and viewport, from `xs` to `xl`. Add any number of unit-less classes for each breakpoint you need and every column will be the same width.
123
 
124
{{< example class="bd-example-row" >}}
125
<div class="container">
126
  <div class="row">
127
    <div class="col">
128
      1 of 2
129
    </div>
130
    <div class="col">
131
      2 of 2
132
    </div>
133
  </div>
134
  <div class="row">
135
    <div class="col">
136
      1 of 3
137
    </div>
138
    <div class="col">
139
      2 of 3
140
    </div>
141
    <div class="col">
142
      3 of 3
143
    </div>
144
  </div>
145
</div>
146
{{< /example >}}
147
 
148
### Equal-width multi-line
149
 
150
Create equal-width columns that span multiple lines by inserting a `.w-100` where you want the columns to break to a new line. Make the breaks responsive by mixing `.w-100` with some [responsive display utilities]({{< docsref "/utilities/display" >}}).
151
 
152
There was a [Safari flexbox bug](https://github.com/philipwalton/flexbugs#flexbug-11) that prevented this from working without an explicit `flex-basis` or `border`. There are workarounds for older browser versions, but they shouldn't be necessary if your target browsers don't fall into the buggy versions.
153
 
154
{{< example class="bd-example-row" >}}
155
<div class="container">
156
  <div class="row">
157
    <div class="col">col</div>
158
    <div class="col">col</div>
159
    <div class="w-100"></div>
160
    <div class="col">col</div>
161
    <div class="col">col</div>
162
  </div>
163
</div>
164
{{< /example >}}
165
 
166
### Setting one column width
167
 
168
Auto-layout for flexbox grid columns also means you can set the width of one column and have the sibling columns automatically resize around it. You may use predefined grid classes (as shown below), grid mixins, or inline widths. Note that the other columns will resize no matter the width of the center column.
169
 
170
{{< example class="bd-example-row" >}}
171
<div class="container">
172
  <div class="row">
173
    <div class="col">
174
      1 of 3
175
    </div>
176
    <div class="col-6">
177
      2 of 3 (wider)
178
    </div>
179
    <div class="col">
180
      3 of 3
181
    </div>
182
  </div>
183
  <div class="row">
184
    <div class="col">
185
      1 of 3
186
    </div>
187
    <div class="col-5">
188
      2 of 3 (wider)
189
    </div>
190
    <div class="col">
191
      3 of 3
192
    </div>
193
  </div>
194
</div>
195
{{< /example >}}
196
 
197
### Variable width content
198
 
199
Use `col-{breakpoint}-auto` classes to size columns based on the natural width of their content.
200
 
201
{{< example class="bd-example-row" >}}
202
<div class="container">
203
  <div class="row justify-content-md-center">
204
    <div class="col col-lg-2">
205
      1 of 3
206
    </div>
207
    <div class="col-md-auto">
208
      Variable width content
209
    </div>
210
    <div class="col col-lg-2">
211
      3 of 3
212
    </div>
213
  </div>
214
  <div class="row">
215
    <div class="col">
216
      1 of 3
217
    </div>
218
    <div class="col-md-auto">
219
      Variable width content
220
    </div>
221
    <div class="col col-lg-2">
222
      3 of 3
223
    </div>
224
  </div>
225
</div>
226
{{< /example >}}
227
 
228
## Responsive classes
229
 
230
Bootstrap's grid includes five tiers of predefined classes for building complex responsive layouts. Customize the size of your columns on extra small, small, medium, large, or extra large devices however you see fit.
231
 
232
### All breakpoints
233
 
234
For grids that are the same from the smallest of devices to the largest, use the `.col` and `.col-*` classes. Specify a numbered class when you need a particularly sized column; otherwise, feel free to stick to `.col`.
235
 
236
{{< example class="bd-example-row" >}}
237
<div class="container">
238
  <div class="row">
239
    <div class="col">col</div>
240
    <div class="col">col</div>
241
    <div class="col">col</div>
242
    <div class="col">col</div>
243
  </div>
244
  <div class="row">
245
    <div class="col-8">col-8</div>
246
    <div class="col-4">col-4</div>
247
  </div>
248
</div>
249
{{< /example >}}
250
 
251
### Stacked to horizontal
252
 
253
Using a single set of `.col-sm-*` classes, you can create a basic grid system that starts out stacked and becomes horizontal at the small breakpoint (`sm`).
254
 
255
{{< example class="bd-example-row" >}}
256
<div class="container">
257
  <div class="row">
258
    <div class="col-sm-8">col-sm-8</div>
259
    <div class="col-sm-4">col-sm-4</div>
260
  </div>
261
  <div class="row">
262
    <div class="col-sm">col-sm</div>
263
    <div class="col-sm">col-sm</div>
264
    <div class="col-sm">col-sm</div>
265
  </div>
266
</div>
267
{{< /example >}}
268
 
269
### Mix and match
270
 
271
Don't want your columns to simply stack in some grid tiers? Use a combination of different classes for each tier as needed. See the example below for a better idea of how it all works.
272
 
273
{{< example class="bd-example-row" >}}
274
<div class="container">
275
  <!-- Stack the columns on mobile by making one full-width and the other half-width -->
276
  <div class="row">
277
    <div class="col-md-8">.col-md-8</div>
278
    <div class="col-6 col-md-4">.col-6 .col-md-4</div>
279
  </div>
280
 
281
  <!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
282
  <div class="row">
283
    <div class="col-6 col-md-4">.col-6 .col-md-4</div>
284
    <div class="col-6 col-md-4">.col-6 .col-md-4</div>
285
    <div class="col-6 col-md-4">.col-6 .col-md-4</div>
286
  </div>
287
 
288
  <!-- Columns are always 50% wide, on mobile and desktop -->
289
  <div class="row">
290
    <div class="col-6">.col-6</div>
291
    <div class="col-6">.col-6</div>
292
  </div>
293
</div>
294
{{< /example >}}
295
 
296
### Gutters
297
 
298
Gutters can be responsively adjusted by breakpoint-specific padding and negative margin utility classes. To change the gutters in a given row, pair a negative margin utility on the `.row` and matching padding utilities on the `.col`s. The `.container` or `.container-fluid` parent may need to be adjusted too to avoid unwanted overflow, using again matching padding utility.
299
 
300
Here's an example of customizing the Bootstrap grid at the large (`lg`) breakpoint and above. We've increased the `.col` padding with `.px-lg-5`, counteracted that with `.mx-lg-n5` on the parent `.row` and then adjusted the `.container` wrapper with `.px-lg-5`.
301
 
302
{{< example >}}
303
<div class="container px-lg-5">
304
  <div class="row mx-lg-n5">
305
    <div class="col py-3 px-lg-5 border bg-light">Custom column padding</div>
306
    <div class="col py-3 px-lg-5 border bg-light">Custom column padding</div>
307
  </div>
308
</div>
309
{{< /example >}}
310
 
311
### Row columns
312
 
313
Use the responsive `.row-cols-*` classes to quickly set the number of columns that best render your content and layout. Whereas normal `.col-*` classes apply to the individual columns (e.g., `.col-md-4`), the row columns classes are set on the parent `.row` as a shortcut.
314
 
315
Use these row columns classes to quickly create basic grid layouts or to control your card layouts.
316
 
317
{{< example class="bd-example-row" >}}
318
<div class="container">
319
  <div class="row row-cols-2">
320
    <div class="col">Column</div>
321
    <div class="col">Column</div>
322
    <div class="col">Column</div>
323
    <div class="col">Column</div>
324
  </div>
325
</div>
326
{{< /example >}}
327
 
328
{{< example class="bd-example-row" >}}
329
<div class="container">
330
  <div class="row row-cols-3">
331
    <div class="col">Column</div>
332
    <div class="col">Column</div>
333
    <div class="col">Column</div>
334
    <div class="col">Column</div>
335
  </div>
336
</div>
337
{{< /example >}}
338
 
339
{{< example class="bd-example-row" >}}
340
<div class="container">
341
  <div class="row row-cols-4">
342
    <div class="col">Column</div>
343
    <div class="col">Column</div>
344
    <div class="col">Column</div>
345
    <div class="col">Column</div>
346
  </div>
347
</div>
348
{{< /example >}}
349
 
350
{{< example class="bd-example-row" >}}
351
<div class="container">
352
  <div class="row row-cols-4">
353
    <div class="col">Column</div>
354
    <div class="col">Column</div>
355
    <div class="col-6">Column</div>
356
    <div class="col">Column</div>
357
  </div>
358
</div>
359
{{< /example >}}
360
 
361
{{< example class="bd-example-row" >}}
362
<div class="container">
363
  <div class="row row-cols-1 row-cols-sm-2 row-cols-md-4">
364
    <div class="col">Column</div>
365
    <div class="col">Column</div>
366
    <div class="col">Column</div>
367
    <div class="col">Column</div>
368
  </div>
369
</div>
370
{{< /example >}}
371
 
372
You can also use the accompanying Sass mixin, `row-cols()`:
373
 
374
```scss
375
.element {
376
  // Three columns to start
377
  @include row-cols(3);
378
 
379
  // Five columns from medium breakpoint up
380
  @include media-breakpoint-up(md) {
381
    @include row-cols(5);
382
  }
383
}
384
```
385
 
386
## Alignment
387
 
388
Use flexbox alignment utilities to vertically and horizontally align columns. **Internet Explorer 10-11 do not support vertical alignment of flex items when the flex container has a `min-height` as shown below.** [See Flexbugs #3 for more details.](https://github.com/philipwalton/flexbugs#flexbug-3)
389
 
390
### Vertical alignment
391
 
392
{{< example class="bd-example-row bd-example-row-flex-cols" >}}
393
<div class="container">
394
  <div class="row align-items-start">
395
    <div class="col">
396
      One of three columns
397
    </div>
398
    <div class="col">
399
      One of three columns
400
    </div>
401
    <div class="col">
402
      One of three columns
403
    </div>
404
  </div>
405
  <div class="row align-items-center">
406
    <div class="col">
407
      One of three columns
408
    </div>
409
    <div class="col">
410
      One of three columns
411
    </div>
412
    <div class="col">
413
      One of three columns
414
    </div>
415
  </div>
416
  <div class="row align-items-end">
417
    <div class="col">
418
      One of three columns
419
    </div>
420
    <div class="col">
421
      One of three columns
422
    </div>
423
    <div class="col">
424
      One of three columns
425
    </div>
426
  </div>
427
</div>
428
{{< /example >}}
429
 
430
{{< example class="bd-example-row bd-example-row-flex-cols" >}}
431
<div class="container">
432
  <div class="row">
433
    <div class="col align-self-start">
434
      One of three columns
435
    </div>
436
    <div class="col align-self-center">
437
      One of three columns
438
    </div>
439
    <div class="col align-self-end">
440
      One of three columns
441
    </div>
442
  </div>
443
</div>
444
{{< /example >}}
445
 
446
### Horizontal alignment
447
 
448
{{< example class="bd-example-row" >}}
449
<div class="container">
450
  <div class="row justify-content-start">
451
    <div class="col-4">
452
      One of two columns
453
    </div>
454
    <div class="col-4">
455
      One of two columns
456
    </div>
457
  </div>
458
  <div class="row justify-content-center">
459
    <div class="col-4">
460
      One of two columns
461
    </div>
462
    <div class="col-4">
463
      One of two columns
464
    </div>
465
  </div>
466
  <div class="row justify-content-end">
467
    <div class="col-4">
468
      One of two columns
469
    </div>
470
    <div class="col-4">
471
      One of two columns
472
    </div>
473
  </div>
474
  <div class="row justify-content-around">
475
    <div class="col-4">
476
      One of two columns
477
    </div>
478
    <div class="col-4">
479
      One of two columns
480
    </div>
481
  </div>
482
  <div class="row justify-content-between">
483
    <div class="col-4">
484
      One of two columns
485
    </div>
486
    <div class="col-4">
487
      One of two columns
488
    </div>
489
  </div>
490
</div>
491
{{< /example >}}
492
 
493
### No gutters
494
 
495
The gutters between columns in our predefined grid classes can be removed with `.no-gutters`. This removes the negative `margin`s from `.row` and the horizontal `padding` from all immediate children columns.
496
 
497
Here's the source code for creating these styles. Note that column overrides are scoped to only the first children columns and are targeted via [attribute selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors). While this generates a more specific selector, column padding can still be further customized with [spacing utilities]({{< docsref "/utilities/spacing" >}}).
498
 
499
**Need an edge-to-edge design?** Drop the parent `.container` or `.container-fluid`.
500
 
501
```scss
502
.no-gutters {
503
  margin-right: 0;
504
  margin-left: 0;
505
 
506
  > .col,
507
  > [class*="col-"] {
508
    padding-right: 0;
509
    padding-left: 0;
510
  }
511
}
512
```
513
 
514
In practice, here's how it looks. Note you can continue to use this with all other predefined grid classes (including column widths, responsive tiers, reorders, and more).
515
 
516
{{< example class="bd-example-row" >}}
517
<div class="row no-gutters">
518
  <div class="col-sm-6 col-md-8">.col-sm-6 .col-md-8</div>
519
  <div class="col-6 col-md-4">.col-6 .col-md-4</div>
520
</div>
521
{{< /example >}}
522
 
523
### Column wrapping
524
 
525
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.
526
 
527
{{< example class="bd-example-row" >}}
528
<div class="container">
529
  <div class="row">
530
    <div class="col-9">.col-9</div>
531
    <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>
532
    <div class="col-6">.col-6<br>Subsequent columns continue along the new line.</div>
533
  </div>
534
</div>
535
{{< /example >}}
536
 
537
### Column breaks
538
 
539
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 `.row`s, but not every implementation method can account for this.
540
 
541
{{< example class="bd-example-row" >}}
542
<div class="container">
543
  <div class="row">
544
    <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
545
    <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
546
 
547
    <!-- Force next columns to break to new line -->
548
    <div class="w-100"></div>
549
 
550
    <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
551
    <div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
552
  </div>
553
</div>
554
{{< /example >}}
555
 
556
You may also apply this break at specific breakpoints with our [responsive display utilities]({{< docsref "/utilities/display" >}}).
557
 
558
{{< example class="bd-example-row" >}}
559
<div class="container">
560
  <div class="row">
561
    <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
562
    <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
563
 
564
    <!-- Force next columns to break to new line at md breakpoint and up -->
565
    <div class="w-100 d-none d-md-block"></div>
566
 
567
    <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
568
    <div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
569
  </div>
570
</div>
571
{{< /example >}}
572
 
573
## Reordering
574
 
575
### Order classes
576
 
577
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 `12` across all five grid tiers.
578
 
579
{{< example class="bd-example-row" >}}
580
<div class="container">
581
  <div class="row">
582
    <div class="col">
583
      First in DOM, no order applied
584
    </div>
585
    <div class="col order-12">
586
      Second in DOM, with a larger order
587
    </div>
588
    <div class="col order-1">
589
      Third in DOM, with an order of 1
590
    </div>
591
  </div>
592
</div>
593
{{< /example >}}
594
 
595
There are also responsive `.order-first` and `.order-last` classes that change the `order` of an element by applying `order: -1` and `order: 13` (`order: $columns + 1`), respectively. These classes can also be intermixed with the numbered `.order-*` classes as needed.
596
 
597
{{< example class="bd-example-row" >}}
598
<div class="container">
599
  <div class="row">
600
    <div class="col order-last">
601
      First in DOM, ordered last
602
    </div>
603
    <div class="col">
604
      Second in DOM, unordered
605
    </div>
606
    <div class="col order-first">
607
      Third in DOM, ordered first
608
    </div>
609
  </div>
610
</div>
611
{{< /example >}}
612
 
613
### Offsetting columns
614
 
615
You can offset grid columns in two ways: our responsive `.offset-` grid classes and our [margin utilities]({{< docsref "/utilities/spacing" >}}). Grid classes are sized to match columns while margins are more useful for quick layouts where the width of the offset is variable.
616
 
617
#### Offset classes
618
 
619
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.
620
 
621
{{< example class="bd-example-row" >}}
622
<div class="container">
623
  <div class="row">
624
    <div class="col-md-4">.col-md-4</div>
625
    <div class="col-md-4 offset-md-4">.col-md-4 .offset-md-4</div>
626
  </div>
627
  <div class="row">
628
    <div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
629
    <div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
630
  </div>
631
  <div class="row">
632
    <div class="col-md-6 offset-md-3">.col-md-6 .offset-md-3</div>
633
  </div>
634
</div>
635
{{< /example >}}
636
 
637
In addition to column clearing at responsive breakpoints, you may need to reset offsets. See this in action in [the grid example]({{< docsref "/examples/grid" >}}).
638
 
639
{{< example class="bd-example-row" >}}
640
<div class="container">
641
  <div class="row">
642
    <div class="col-sm-5 col-md-6">.col-sm-5 .col-md-6</div>
643
    <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>
644
  </div>
645
  <div class="row">
646
    <div class="col-sm-6 col-md-5 col-lg-6">.col-sm-6 .col-md-5 .col-lg-6</div>
647
    <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>
648
  </div>
649
</div>
650
{{< /example >}}
651
 
652
#### Margin utilities
653
 
654
With the move to flexbox in v4, you can use margin utilities like `.mr-auto` to force sibling columns away from one another.
655
 
656
{{< example class="bd-example-row" >}}
657
<div class="container">
658
  <div class="row">
659
    <div class="col-md-4">.col-md-4</div>
660
    <div class="col-md-4 ml-auto">.col-md-4 .ml-auto</div>
661
  </div>
662
  <div class="row">
663
    <div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>
664
    <div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>
665
  </div>
666
  <div class="row">
667
    <div class="col-auto mr-auto">.col-auto .mr-auto</div>
668
    <div class="col-auto">.col-auto</div>
669
  </div>
670
</div>
671
{{< /example >}}
672
 
673
## Nesting
674
 
675
To nest your content with the default grid, add a new `.row` and set of `.col-sm-*` columns within an existing `.col-sm-*` column. Nested rows should include a set of columns that add up to 12 or fewer (it is not required that you use all 12 available columns).
676
 
677
{{< example class="bd-example-row" >}}
678
<div class="container">
679
  <div class="row">
680
    <div class="col-sm-9">
681
      Level 1: .col-sm-9
682
      <div class="row">
683
        <div class="col-8 col-sm-6">
684
          Level 2: .col-8 .col-sm-6
685
        </div>
686
        <div class="col-4 col-sm-6">
687
          Level 2: .col-4 .col-sm-6
688
        </div>
689
      </div>
690
    </div>
691
  </div>
692
</div>
693
{{< /example >}}
694
 
695
## Sass mixins
696
 
697
When using Bootstrap's source Sass files, you have the option of using Sass variables and mixins to create custom, semantic, and responsive page layouts. Our predefined grid classes use these same variables and mixins to provide a whole suite of ready-to-use classes for fast responsive layouts.
698
 
699
### Variables
700
 
701
Variables and maps determine the number of columns, the gutter width, and the media query point at which to begin floating columns. We use these to generate the predefined grid classes documented above, as well as for the custom mixins listed below.
702
 
703
```scss
704
$grid-columns:      12;
705
$grid-gutter-width: 30px;
706
 
707
$grid-breakpoints: (
708
  // Extra small screen / phone
709
  xs: 0,
710
  // Small screen / phone
711
  sm: 576px,
712
  // Medium screen / tablet
713
  md: 768px,
714
  // Large screen / desktop
715
  lg: 992px,
716
  // Extra large screen / wide desktop
717
  xl: 1200px
718
);
719
 
720
$container-max-widths: (
721
  sm: 540px,
722
  md: 720px,
723
  lg: 960px,
724
  xl: 1140px
725
);
726
```
727
 
728
### Mixins
729
 
730
Mixins are used in conjunction with the grid variables to generate semantic CSS for individual grid columns.
731
 
732
```scss
733
// Creates a wrapper for a series of columns
734
@include make-row();
735
 
736
// Make the element grid-ready (applying everything but the width)
737
@include make-col-ready();
738
@include make-col($size, $columns: $grid-columns);
739
 
740
// Get fancy by offsetting, or changing the sort order
741
@include make-col-offset($size, $columns: $grid-columns);
742
```
743
 
744
### Example usage
745
 
746
You can modify the variables to your own custom values, or just use the mixins with their default values. Here's an example of using the default settings to create a two-column layout with a gap between.
747
 
748
```scss
749
.example-container {
750
  @include make-container();
751
  // Make sure to define this width after the mixin to override
752
  // `width: 100%` generated by `make-container()`
753
  width: 800px;
754
}
755
 
756
.example-row {
757
  @include make-row();
758
}
759
 
760
.example-content-main {
761
  @include make-col-ready();
762
 
763
  @include media-breakpoint-up(sm) {
764
    @include make-col(6);
765
  }
766
  @include media-breakpoint-up(lg) {
767
    @include make-col(8);
768
  }
769
}
770
 
771
.example-content-secondary {
772
  @include make-col-ready();
773
 
774
  @include media-breakpoint-up(sm) {
775
    @include make-col(6);
776
  }
777
  @include media-breakpoint-up(lg) {
778
    @include make-col(4);
779
  }
780
}
781
```
782
 
783
{{< example >}}
784
<div class="example-container">
785
  <div class="example-row">
786
    <div class="example-content-main">Main content</div>
787
    <div class="example-content-secondary">Secondary content</div>
788
  </div>
789
</div>
790
{{< /example >}}
791
 
792
## Customizing the grid
793
 
794
Using our built-in grid Sass variables and maps, it's possible to completely customize the predefined grid classes. Change the number of tiers, the media query dimensions, and the container widths—then recompile.
795
 
796
### Columns and gutters
797
 
798
The number of grid columns can be modified via Sass variables. `$grid-columns` is used to generate the widths (in percent) of each individual column while `$grid-gutter-width` sets the width for the column gutters.
799
 
800
```scss
801
$grid-columns: 12 !default;
802
$grid-gutter-width: 30px !default;
803
```
804
 
805
### Grid tiers
806
 
807
Moving beyond the columns themselves, you may also customize the number of grid tiers. If you wanted just four grid tiers, you'd update the `$grid-breakpoints` and `$container-max-widths` to something like this:
808
 
809
```scss
810
$grid-breakpoints: (
811
  xs: 0,
812
  sm: 480px,
813
  md: 768px,
814
  lg: 1024px
815
);
816
 
817
$container-max-widths: (
818
  sm: 420px,
819
  md: 720px,
820
  lg: 960px
821
);
822
```
823
 
824
When making any changes to the Sass variables or maps, you'll need to save your changes and recompile. Doing so will output a brand new set of predefined grid classes for column widths, offsets, and ordering. Responsive visibility utilities will also be updated to use the custom breakpoints. Make sure to set grid values in `px` (not `rem`, `em`, or `%`).