Strange headroom on `display: inline-block`-elements
I have 6 DIV
s display:inline-block
in one line. But they have a strange empty space between them, how can I get rid of this? They should be inserted into the container on one line.
Fiddle: http://jsfiddle.net/y7L7q/
HTML:
<div id="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
CSS
#container{
width:300px;
border:1px solid black;
}
.box{
display:inline-block;
height:50px;
width:50px;
background-color:black;
margin:0;
padding:0;
}
source to share
Write font-size:0;
. Like this:
#container{
width:300px;
border:1px solid black;
font-size:0;
}
Check it out http://jsfiddle.net/y7L7q/1/
OR
Write your sign like this:
<div id="container">
<div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div><div class="box"></div>
</div>
Check it out http://jsfiddle.net/y7L7q/2/
source to share
Since they are set to inline-block, this means that the spaces in between are treated as inline spaces and therefore appear as such. You can fix this by putting all divs on one line in the html or by wrapping a space in the comments:
<div class="box"></div><!--
--><div class="box"></div>
source to share
This is a common problem with display: inline-block
. You have multiple solutions, remove newlines (or comment them out: http://jsfiddle.net/eaqfk/ ), install font-size: 0
, install margin-right: -4px
.
Everything in this question: CSS: the problem with the dropdown
source to share