1

I am seeing weird margins when using inline-block for divs. This happens in chrome, firefox and safari.

Code and code pen: http://codepen.io/lukaMis/pen/fknIg

<div class="wrapper">
 <div class="smallColumn"></div>
 <div class="smallColumn"></div>
 <div class="smallColumn"></div>
 <div class="smallColumn"></div>
</div>

*, *:after, *:before {
 -webkit-box-sizing: border-box;
 -moz-box-sizing: border-box;
  box-sizing: border-box;
  margin: 0px;
  padding: 0px;
}
.wrapper {
 position: relative;
 width: 1024px;
 height: 192px;
 margin: 20px auto 0 auto;
 background: rgba(0,0,0,0.2);
}
.smallColumn {
 width: 20%;
 height: 192px;
 background: green;
 display: inline-block;
}

Can i get rid of these margins without float-ing?

tnx Have a nice day Luka

Luka Mis
  • 543
  • 1
  • 7
  • 18
  • 1
    possible duplicate of [How to remove the space between inline-block elements?](http://stackoverflow.com/questions/5078239/how-to-remove-the-space-between-inline-block-elements) – Hashem Qolami Aug 23 '14 at 10:59

1 Answers1

1

Add font-size: 0 to the .wrapper class.

CSS

.wrapper {
  position: relative;
  width: 1024px;
  height: 192px;
  margin: 20px auto 0 auto;
  background: rgba(0,0,0,0.2);
  font-size: 0;
}

Here is the amended CodePen: http://codepen.io/anon/pen/aGExt.

Kai Feller
  • 653
  • 3
  • 14