Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap container-fluid - remove margins the right way (overflow)

How can I remove all margins from boostrap container-fluid class and its rows?

.container-fluid { padding: 0;}

This does basically what I want, but it adds 20px overflow to body. So should I just do this:

body, html { overflow-x: hidden; }

Do something with .container-fluid > .row

like image 456
niksos Avatar asked Oct 05 '14 15:10

niksos


People also ask

How do I remove a container margin in Bootstrap?

So the answer is: . container-fluid > . row -- make the margin:0 on the left and right if you remove the padding on the left and right of the column classes.

Do Bootstrap containers have padding?

Containers are a fundamental building block of Bootstrap that contain, pad, and align your content within a given device or viewport.


1 Answers

To be specific about your question:

The .row has a negative left and right margin equal to the left/right padding value of the col-*-*, that is why there are horizontal scrollbars when you fiddle with the grid without understanding how it works. If you manipulate the column classes with zero padding on the left and right or with some other value, the negative margin on the .row must be equal to the the padding on the left and right of the column classes. The .container also has padding that matches the value of the column classes to prevent the scrollbars.

So the answer is: .container-fluid > .row -- make the margin:0 on the left and right if you remove the padding on the left and right of the column classes. If all is zero, then you can just adjust the .container or .container fluid with zero padding on the left and right, but if you use different values > 15px L & R, then it's a different story as the .container/.container-fluid will need to be adjusted if the left and right padding on the columns is greater than 15px.

There are no margins on the col-*-* it's padding which is quite different when you use box-sizing:border-box globally as Boostrap 3 does.

If you want a tight grid, remove all padding on the left and right of all column classes and then remove the negative margin on the left and right of the .row, and then you can remove the left and right padding on the .container.

DEMO: http://jsbin.com/jeqase/2/

Removes all padding and negative margin for a tight grid and full width of the .container with any surrounding element (body, html, whatever) with the class .alt-grid:

.alt-grid [class*="col-"] {padding-left:0;padding-right:0}
.alt-grid .row {margin-left:0;margin-right:0}

/* container adjusted */
.alt-grid .container {width:100%;max-width:none;padding:0;}

You can also do this with .container-fluid - the only thing to zero out is the left and right padding.

like image 105
Christina Avatar answered Oct 19 '22 04:10

Christina