I’ve been using bootstrap for quite a while now and I’m facing this problem for the first time. I really don’t know how to do this. I have found many people suggesting to just remove padding-left
on the first-child
element and the last one. I also tried this way at first but then I realized that it couldn’t work, since the .col
class has the box-sizing: border-box;
property which makes the div to have padding included in the width. (Which is obviously necessary if you want a clean layout using width: 25%;
).
So, if you remove these padding on the left, the first and last div are going to be 15px larger, which breaks the layout… I want every col div to have exactly the same width, I want them to fit 100% of the row and have no padding left or right. Is there a class that I’m not aware of in bootstrap?
Is it possible while keeping the Bootstrap 3 templating system?
Code example:
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
</div>
3
Answers
I finaly found a way around it by creating my own class, that I believe respect the way bootstrap made their layouting system. Here was the best and minimal way to do it:
CSS
HTML
This way, I achieve exactly what I want, it's reusable and respect the Twitter's Bootstrap thinking (I believe). Thanks to Deja Vu who leaded me to the calc thiking, I believe it's a good way to achieve this. But you cannot put 15 margin left on the first child and right on the last child since that would still create a gutter around but using the margin.
I wasn’t able to solve your problem but I have 2 ideas and maybe it will lead you to the solution.
Replace
padding
s withmargin
shtml
css
Not sure if that would satisfy your design requirements.
recalc width
css
The problem I faced was – in both cases last child falls onto the separate row:
fiddle.
Hope this will give you some food-for-thought.
I could not comment on Yann Chabot’s post, but as an extension on it, I would recommend to use escape values. If you don’t use this, Chrome recalculates the width to 10% instead of the correct width.
CSS