Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Bootstrap 4 Basics (Retired) Getting to Know Bootstrap 4 Creating a Simple Page

Loris Guerra
Loris Guerra
17,536 Points

Adding a ".container" <div> inside another ".container" <div>

Why is considered a bad practice to add a ".container" inside another ".container"?

<div class="container">
  <h1>Title</h1>
  <div class="navbar">
    .. some stuff here ..
  </div>

  <div class="container">
    .. other content here ..
  </div>

</div>

I tried, but I couldn't find any issues on it, Bootstrap only applies more margin on both left and right.

1 Answer

Rune Andreas Nielsen
Rune Andreas Nielsen
5,354 Points

Hi, Loris.

Bootstraps 'container' class is used to set the contents margin to deal with responsive design.

The reason it would be considered a bad practice to use it multiple places on the same web page is that its main purpose is to deal with responsive design and not as a styling element.

Your code won't break using it, but a better approach would be to create your own element with margin, if you need the styling that the 'container' class provides.