Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple and/or nested Bootstrap containers?

My understanding is that all Bootstrap-styled elements must exist inside a <div class="container"> element. But sometimes I see Bootstrap examples where there are multiple "containers":

<div class="container">     <!-- Blah, GUI stuff, blah --> </div>  ...  <div class="container">     <!-- Blah, more GUI stuff, blah --> </div> 

My questions:

  1. When would you ever need a single HTML page with multiple "container divs"? What benefit does this offer as opposed to just putting the entire body inside one big "container div"?
  2. Would you ever want to nest "container divs" inside other ones? When/why?
like image 544
smeeb Avatar asked Oct 20 '14 15:10

smeeb


People also ask

Can I have multiple containers in Bootstrap?

Docs: Bootstrap requires a containing element to wrap site contents and house our grid system. You may choose one of two containers to use in your projects.

What are different types of containers in Bootstrap?

Bootstrap comes with three different containers: .container , which sets a max-width at each responsive breakpoint. .container-fluid , which is width: 100% at all breakpoints. .container-{breakpoint} , which is width: 100% until the specified breakpoint.

Can I have 2 containers in HTML?

Its is not illegal to use multiple containers. You can use as many as you want. e.g if you want to have multiple sections on a page with different background image or color, you can use sections and within each section you can use a container.


1 Answers

  1. Some sections of the page will span the full viewport width and others won't. Some backgrounds will be the full width but the content won't.

    An example of this is a featurette area which has a background image or color that is the full width of the viewport but the content inside that, forms or whatever, don't exceed the .container at any given viewport width.

  2. You don't nest .container or .container-fluid -- see the docs. It's not necessary.

    Docs: Bootstrap requires a containing element to wrap site contents and house our grid system. You may choose one of two containers to use in your projects. Note that, due to padding and more, neither container is nestable [neither means that .container and .container-fluid are NOT to be nested].

like image 196
Christina Avatar answered Sep 24 '22 04:09

Christina