4

Why is an empty space between divs when using display: inline-block, like in this example: http://jsbin.com/IhULuZO/1/edit.

I know I can use float:left, but I want to get rid of the empty space without floating elements if possible.

Tamás Pap
  • 17,777
  • 15
  • 70
  • 102
  • 1
    may be [this](http://stackoverflow.com/questions/1833734/display-inline-block-extra-margin) and [this](http://stackoverflow.com/questions/14241696/how-to-get-rid-of-space-between-divs-when-display-inline-block-and-stacked-horiz) can help you.. – Sohail Oct 31 '13 at 10:06

4 Answers4

8

Because the indentation of your code technically is a bunch of whitespace.

<div class="parent">
    <div class="child"></div><div class="child"></div><div class="child"></div>
</div>
slugster
  • 49,403
  • 14
  • 95
  • 145
nicks
  • 134
  • 7
2

there is that space between those divs to make them more readable. To delete these spaces, comment all the space in html like this :

  <div class="parent">
    <div class="child"></div><!--
    --><div class="child"></div><!--
    --><div class="child"></div>
  </div>
Guillaume Lhz
  • 904
  • 5
  • 16
1

It is happening because you have written .child divs on separate lines. If you write them on same line, extra space will be removed.

<div class="parent">
    <div class="child"></div><div class="child"></div><div class="child"></div>
</div>
slugster
  • 49,403
  • 14
  • 95
  • 145
codingrose
  • 15,563
  • 11
  • 39
  • 58
1

You should remove the space between .child divs and Code Should Appear Like these.

<div class="parent">
    <div class="child"></div><div class="child"></div><div class="child"></div>
 </div>
slugster
  • 49,403
  • 14
  • 95
  • 145