I'd like my content to be fluid, but when using .container-fluid
with Bootstrap's grid, I'm still seeing padding.
How can I get rid of the padding?
I see that I don't get the padding with .row
, but I want to add columns, and as soon as I do, the padding is back.
I want to be able to use the columns at full width.
An example:
<div class="container-fluid"> <div class="row"> <div class="col-sm-6"> <p>Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p> </div> <div class="col-sm-6"> <p>Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p> </div> </div>
Solution I've got:
Override bootstrap.css, linke 1427 & 1428 (v3.2.0)
padding-right: 15px; padding-left: 15px;
to
padding-right: 0px; padding-left: 0px;
As an improvement of this answer, you can easily remove padding and avoid the horizontal scrollbar simply adding the no-gutters class to the row element. This removes the negative margins as stated by the official documentation getbootstrap.com/docs/4.0/layout/grid/#no-gutters. So, no further css rules are needed.
If you want to remove the padding for all the screens then you can go to your theme module and set padding as 0px for the top, left, and right. If you want to do the same for a specific screen you add a new CSS class from Style editor of the screen.
Containers are a fundamental building block of Bootstrap that contain, pad, and align your content within a given device or viewport.
. container has a max width pixel value, whereas . container-fluid is max-width 100%.
You should also add a "row" to each container which will "fix" this issue!
<div class="container-fluid"> <div class="row"> Some text </div> </div>
See http://jsfiddle.net/3px20h6t/
5+ years passed, and it's quite strange that there are so many answers there which don't follow (or are against) bootstrap rules or don't actually answer the question...
(For the details on those mistakes check the last section of this answer)
Short Answer:
Simply use Bootstrap's no-gutters
class for (Bootstrap 4) OR g-0
for (Bootstrap 5) in your row to remove padding:
<div class="container-fluid"> <!-- For Boostrap 4, use this instead: <div class="row no-gutters">--> <div class="row g-0"> <div class="col-sm-6"> <p>Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p> </div> <div class="col-sm-6"> <p>Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p> </div> </div> </div>
(Also you've forgotten to add </div>
to the end of your file. It's fixed in the code above as well)
Note:
There are cases when you want to remove the padding of the container itself as well. In this case consider dropping .container
or .container-fluid
classes as recommended by the documentation.
<!--<div class="container-fluid">--> <div class="row no-gutters"> <div class="col-sm-6"> <p>Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p> </div> <div class="col-sm-6"> <p>Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p> </div> </div> <!--</div>-->
Long Answer:
The paddings you get are actually documented in Bootstrap's documentation:
Rows are wrappers for columns. Each column has horizontal padding (called a gutter) for controlling the space between them. This padding is then counteracted on the rows with negative margins. This way, all the content in your columns is visually aligned down the left side.
And about the solution, which was documented as well:
Columns have horizontal padding to create the gutters between individual columns, however, you can remove the margin from rows and padding from columns with .no-gutters on the .row.
Regarding dropping the container:
Need an edge-to-edge design? Drop the parent .container or .container-fluid.
Bonus: About the mistakes found on the other answers
col
-s and wrapped them with row
-s as documentation says:In a grid layout, content must be placed within columns and only columns may be immediate children of rows.
px-0
for removing horizontal paddings instead pl-0 pr-0
or reinventing your styles.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With