Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Bootstrap .container and .container-fluid classes?

Just downloaded 3.1 and found in the docs...

Turn any fixed-width grid layout into a full-width layout by changing your outermost .container to .container-fluid.

Looking in bootstrap.css, it appears that .container-fluid is identical to .container. Both have the same CSS, and every instance of .container-fluid is paired with .container, and all column classes are specified in percentages.

When twiddling with examples I could not see any difference, as everything seemed fluid.

As I'm new to Bootstrap, I assume I'm missing something. Could someone take a minute and enlighten me?

like image 494
FatFingers Avatar asked Mar 07 '14 22:03

FatFingers


People also ask

What is the difference between .container and container-fluid *?

container-fluid covers the whole width of any device, . container is set to cover a maximum of 1320px width on the largest viewports. If you use the container class and your current browser width is 1350px, it will adjust to 1140px wide.

What is Bootstrap container-fluid?

container-fluid: The . container-fluid class provides a full-width container which spans the entire width of the viewport. In the below example, the div with class “container-fluid” will take up the complete width of the viewport and will expand or shrink whenever the viewport is resized. HTML.

What is Bootstrap and explain the Bootstrap classes and container?

In Bootstrap, container is used to set the content's margins dealing with the responsive behaviors of your layout. It contains the row elements and the row elements are the container of columns (known as grid system). The container class is used to create boxed content.

How many types of container classes are available in Bootstrap?

There are three different containers available in Bootstrap: . container , which sets a max-width at each responsive breakpoint.


1 Answers

Quick version: .container has one fixed width for each screen size in bootstrap (xs,sm,md,lg); .container-fluid expands to fill the available width.


The difference between container and container-fluid comes from these lines of CSS:

@media (min-width: 568px) {   .container {     width: 550px;   } } @media (min-width: 992px) {   .container {     width: 970px;   } } @media (min-width: 1200px) {   .container {     width: 1170px;   } } 

Depending on the width of the viewport that the webpage is being viewed on, the container class gives its div a specific fixed width. These lines don't exist in any form for container-fluid, so its width changes every time the viewport width changes.

So for example, say your browser window is 1000px wide. As it's greater than the min-width of 992px, your .container element will have a width of 970px. You then slowly widen your browser window. The width of your .container won't change until you get to 1200px, at which it will jump to 1170px wide and stay that way for any larger browser widths.

Your .container-fluid element, on the other hand, will constantly resize as you make even the smallest changes to your browser width.

like image 112
JKillian Avatar answered Oct 20 '22 17:10

JKillian