Skip to content
Tutorials Center
My learning

Topics

Lesson 9 of 58 ยท Layout

Nested Grids and Full Layouts

Nest rows inside Bootstrap columns, build a dashboard and a blog layout from the 12-column grid, avoid common layout mistakes, and meet the optional CSS grid.

So far every row in this chapter has been a single layer: a container, a row, some columns. Real pages are rarely that simple. A dashboard card may hold a pair of statistics side by side, and a blog post may show a photo gallery inside its main column. Bootstrap handles this with nesting: you put a new row inside a column, and that row gets its own fresh set of twelve columns.

In this lesson you will learn the nesting rule, put the whole chapter together in two complete layouts (a dashboard and a blog), review the mistakes that cause most grid bugs, and take a short look at Bootstrap's optional CSS grid. You should know responsive columns and gutters and alignment first.

The nesting rule

To nest, add a .row inside a .col, then put columns inside that row. The new row divides the width of its parent column, not the width of the page.

HTML
<div class="row">
  <div class="col-md-8">
    Level one, 8 of 12
    <div class="row">
      <div class="col-6">Level two, half of the 8</div>
      <div class="col-6">Level two, half of the 8</div>
    </div>
  </div>
  <div class="col-md-4">Level one, 4 of 12</div>
</div>

Three details make this work:

  • The nested row always sits inside a column, never directly inside another row.
  • The nested columns add up to 12 again, because 12 is relative to the parent. Two col-6 inside an 8-wide column each get half of that column.
  • You do not need another .container. The outermost container is enough, and a nested one would add unwanted padding and max-widths.
flowchart TD
  C["container"] --> R1["row"]
  R1 --> A["col-md-8"]
  R1 --> B["col-md-4"]
  A --> R2["nested row"]
  R2 --> A1["col-6"]
  R2 --> A2["col-6"]

A nested row lives inside a column and starts its own 12-column count.

Why does the nested row not overflow? Remember that rows have negative side margins that cancel the padding of the columns around them. The nested row's negative margin cancels the padding of its parent column in the same way, so the nested content lines up with the parent's text.

A nested row

The inner pairs (6+6 and 4+8) both fill the parent exactly. Change the numbers and watch the extra column wrap, just as in a top-level row.

Layout 1: a dashboard

A dashboard is mostly nesting plus responsive columns. The recipe: a sidebar column, a main column, and in the main column a row of statistic cards followed by a wider chart area and a narrower activity list.

Cards, navs and tables get their own lessons later; here simple bordered boxes stand in for them, so you can focus on the structure.

Dashboard layout

Study how the pieces nest:

  1. The outer row splits the page into col-lg-2 (menu) and col-lg-10 (main).
  2. Inside main, two separate rows follow each other. The first uses row-cols-2 row-cols-md-4 for the statistic cards: two per line on phones, four from md.
  3. The second row holds the chart and activity panels, which only sit side by side from xl.
  4. Equal-height panels come from height: 100% on each panel (Bootstrap's h-100 utility does the same), which works because the columns in a row already stretch to equal height.

Notice that container-fluid is used here. A dashboard wants the full window width, while content pages usually look better in a limited container.

Layout 2: a blog page

A blog layout is simpler: one wide column for articles, one narrow column for widgets. The interesting part is the post preview, which has an image on one side and text on the other, and it nests a row to do so.

Blog layout

Each article is a nested row: photo on the left (4 of 12) and text on the right (8 of 12) from sm upward, stacked on phones. The align-items-center class from the previous lesson keeps the text centered next to the picture. The page headings use h1 with the h3 class, which restyles size without changing the heading level; typography is covered in Typography.

Common layout mistakes

Most "the grid is broken" questions have one of these causes:

  • A row without a column inside. Putting text or a card straight into .row removes the column padding and the proper width logic, so content touches the edges or overflows. Always wrap the content in a column.
  • A row directly inside a row. The nested row must sit inside a col-*. Otherwise the negative margins add up and you get a horizontal scrollbar.
  • Columns outside a row. Without the row, there is no flex container, so the widths do nothing.
  • Another container inside a column. Containers set their own max-width and side padding. Use rows for nesting.
  • Nesting too deeply. Three levels deep is already hard to read. If you need more, ask whether flex utilities, such as those in Flex Utilities, would be simpler.
  • Using the grid for everything. The grid arranges page regions. Small arrangements, like an icon next to a label, are easier with d-flex and gap.

Debug with outlines. When a layout looks wrong, add a temporary style such as .row, .row > * { outline: 1px solid red; }. Seeing where each row and column begins usually reveals the missing or extra wrapper in seconds.

An optional alternative: the CSS grid

Bootstrap's default grid is built on flexbox. Since version 5.1 there is also an opt-in layout system built on CSS Grid, for cases where you need rows and columns together, such as items spanning two rows. It is not included in the CDN files you have been using. You turn it on in Sass with $enable-cssgrid: true, usually together with $enable-grid-classes: false, and then build your own CSS.

This snippet is read-only, because it needs a custom Sass build (see Customizing with Sass):

HTML
<div class="grid">
  <div class="g-col-12 g-col-md-8">Main</div>
  <div class="g-col-12 g-col-md-4">Side</div>
</div>

The names change: .grid replaces .row, g-col-* replaces col-*, and the gap is set with the --bs-gap variable instead of gutters. The big difference is that grid items don't need the negative-margin trick, and nesting works differently (you set the number of columns with --bs-columns). For almost every site, the standard flexbox grid is the right choice; reach for the CSS grid only when you really need two-dimensional placement.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where does a nested row belong?

    A nested row must sit inside a col-* element. The column's padding and the row's negative margins then cancel out.
  2. 2. A nested row inside a col-md-8 contains two col-6 elements. How wide is each of them?

    The nested row has its own 12 units, measured against the width of the parent column.
  3. 3. Text placed directly inside .row, with no column around it, usually causes what problem?

    Columns provide the gutter padding. Without one, the row's negative margins push the content outward.
  4. 4. Which statement about Bootstrap's CSS grid is correct?

    Enable it with the $enable-cssgrid Sass variable. The compiled CDN stylesheet uses the flexbox grid only.

Summary

  • Nest a layout by putting a .row inside a .col-*; the nested columns count to 12 again, relative to the parent.
  • Use one outer container only; dashboards often use container-fluid.
  • A dashboard is a sidebar row plus rows of row-cols-* statistic cards and responsive panels; a blog is a wide column, a narrow column and nested rows for post previews.
  • Always keep the structure container, row, column. Missing or extra wrappers cause most layout bugs.
  • Bootstrap's CSS grid is an optional Sass feature for two-dimensional layouts; the flexbox grid covers most pages.

Next lesson: Sizing Utilities.