I've never came across this issue, but in a nutshell I apply border box as my box-sizing to all the elements:
*, *:before, *:after {
-webkit-box-sizing: border-box !important;
-moz-box-sizing: border-box !important;
-ms-box-sizing: border-box !important;
box-sizing: border-box !important;
}
I than have a responsive column layout, in this case 3 columns per row
<div class="row clearfix">
<div class="column span-4-12 property">
<p>..</p>
</div>
<!-- more divs here -->
</div>
All spans nicely across 3 columns until I add margin to .property div, now usually because of border-box this would simply add margin between the columns and leave them 3 in a row, but now for some reason 3rd column is pushed to a new row, I honestly don't understand why, am I missing something?
Here is live example on jsFiddle: http://jsfiddle.net/NmrZZ/
Depending on the situation, there's good reasons for using either border-box or content-box. When creating something that needs precision in terms of size relative to others on the same row (e.g. a grid system that needs to total 100% per row), using border-box will simplify things and reduce surprises.
Note :- when using box-sizing : content-box; the content size remain same while border-box size grows as padding and border grow.
The box-sizing property allows us to include the padding and border in an element's total width and height. If you set box-sizing: border-box; on an element, padding and border are included in the width and height: Both divs are the same size now!
border-box tells the browser to account for any border and padding in the values you specify for an element's width and height. If you set an element's width to 100 pixels, that 100 pixels will include any border or padding you added, and the content box will shrink to absorb that extra width.
Margin is not part of the box-model (whatever box-sizing you use), so it will always be in addition to the width + padding + border you've declared.
The image below (from the CSS Tricks article on this topic) illustrates the difference between the standard box-model and box-sizing: border-box
:
The best advice I can give is to avoid margins for your grid entirely, and to keep it separate from your presentation. This means more markup, but will save you headaches and make things much easier to maintain. Check out this fork of your example. The amended CSS:
.span-4-12 {
width: 33.33%;
padding-left: 2%;
}
.property {
background: white;
}
And the new markup will be:
<div class="column span-4-12">
<div class="property">
<p>Some text 1</p>
</div>
</div>
It's a float clear problem. Instead of float you can use inline-block as float is outdated. Most people now use display:inline-block
as there is no need to write clear
for separate line.
Refer:
*, *:before, *:after {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box !important;
-moz-box-sizing: border-box !important;
-ms-box-sizing: border-box !important;
box-sizing: border-box !important;
}
body {
background: grey;
}
}
.row {
clear: both;
}
.clearfix:before,
.clearfix:after {
content:"";
display:table;
}
.clearfix:after {
clear:both;
}
.clear {
zoom:1;
}
.column {
display: inline-block;
}
.span-4-12 {
width: 30%;
}
.property {
background: white;
margin-left: 2%;
}
<div class="row clearfix">
<div class="column span-4-12 property">
<p>Some text 1</p>
</div>
<div class="column span-4-12 property">
<p>Some text 2</p>
</div>
<div class="column span-4-12 property">
<p>Some text 3</p>
</div>
</div>
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