Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding padding or margin breaks float

I tried to create CSS grid like bootstrap col. I want to add a padding of 15px from the left and the right. But when I add the attribute it breaks the float (makes it to not stand side by side).

Here is the example: https://jsfiddle.net/t29q1gcL/

Why didn't it work?

.grid-4{
  float: left;
  width: 40%;
  background: red;
  padding: 0 15px;
}

.grid-6{
  float: left;
  width: 60%;
  background: blue;
  padding: 0 15px;
}
like image 282
GerryofTrivia Avatar asked Jun 21 '26 23:06

GerryofTrivia


2 Answers

add this to your css, reference link http://www.w3schools.com/cssref/css3_pr_box-sizing.asp

* {
   box-sizing:border-box;
  -webkit-box-sizing:border-box;
  -ms-box-sizing:border-box;
  -moz-box-sizing:border-box;
}

check with the working fiddle https://jsfiddle.net/d8mrdz7x/

like image 141
Jishnu V S Avatar answered Jun 24 '26 09:06

Jishnu V S


Add: "box-sizing: border-box;"

.grid-4{
  float: left;
  width: 40%;
  background: red;
  padding: 0 15px;
  box-sizing:border-box;
}

.grid-6{
  float: left;
  width: 60%;
  background: blue;
  padding: 0 15px;
  box-sizing:border-box;
}

.clearfix{
  clear: both;
}
like image 30
Uladzimir Avatar answered Jun 24 '26 07:06

Uladzimir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!