Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need to use Bootstrap's "container" and "row" if your content is to span the whole width?

I think the standard of Bootstrap 3 and 4 is

<div class="container">
    <div class="row">
        <div class="col-md-4"> ... </div>
        <div class="col-md-8"> ... </div>   <!-- just add up to 12 -->
    </div>
</div>

But what if you have a div, table, form, or any element, that you plan to just let it span the whole width? Then do you need the container or row or col-md-12 at all, for the whole page to display well under the styling rules of Bootstrap 3 and 4?

P.S. if possible, please point to or quote the official Bootstrap docs related to this.

like image 965
nonopolarity Avatar asked Apr 02 '17 17:04

nonopolarity


People also ask

Can I use row without container in Bootstrap?

Without the container it kind a works - but it shows a horizontal scroll bar at the bottom of the page and around 20px are cut off from rightside of the screen. See yourself how it works without the container class - just go to http://getbootstrap.com/ and remove the container class using inspect element.

When should I use Bootstrap rows?

The bootstrap row class is used to make a horizontal layout to contain column class on the web page. The bootstrap row is divided space and makes columns using col class in the bootstrap grid system. The bootstrap row class is used to make a horizontal layout to contain column class on the web page.

When should I use column and row in Bootstrap?

Some Bootstrap grid system rules: Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for proper alignment and padding. Use rows to create horizontal groups of columns. Content should be placed within columns, and only columns may be immediate children of rows.

Which Bootstrap layout class should be used for full width container spanning the entire width of the viewport?

container-fluid class provides a full width container, spanning the entire width of the viewport.


2 Answers

Short answer: you do need to use container, but you don't need to use row.

You can put elements directly in the container or container-fluid. You aren't required to use the grid (.row and .col-*), and the container alone can be used as a container of content. Only use the grid when you need the responsive 12-unit structure.

For example, this is valid Bootstrap...

<div class="container">
   <h2>Hello World</h2>
   <p class="lead">Some other content...</p>
</div>

From the Bootstrap docs...

"Bootstrap requires a containing element to wrap site contents and house our grid system."

So, the purpose of container is two-fold: 1) to "house the grid system", and 2) to "wrap site contents". However, when you do use the grid (.row and .col-*), a container is required to wrap the .row.

Even the basic starter template utilizes container without the grid.

In summary...

  • You can use .container or .container-fluid alone to contain elements and page content.
  • If you use the grid (.row and .col-*), .row must be inside a .container or .container-fluid, and .col-* must be inside a .row.
like image 177
Zim Avatar answered Sep 20 '22 09:09

Zim


You should add .container-fluid to your wrapping div. You should wrap the table, div, or form within a div add the class .container-fluid to it.

The official bootstrap documentation on grid system

like image 37
neophyte Avatar answered Sep 20 '22 09:09

neophyte