I have 6 DIV
s with display:inline-block
in one line. But they have a strange white space between each other, how can I get rid of that? They should fit in the container in 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;
}
Because they are set to inline block this means the whitespace between them is treated as inline whitespace, and therefore rendered as such. You can fix this by either by putting all the divs on one line in the html or wrapping the white space in comments:
It's a common issue with
display: inline-block
. You have a few solution, delete new lines (or comment them : http://jsfiddle.net/eaqfk/), setfont-size: 0
, setmargin-right: -4px
.Everything is on this question : CSS: Spacing issue with dropdown
Instead of display:inline-block, use float:left to remove the unwanted space. Check this out.
http://jsfiddle.net/y7L7q/9/
Also note that font-size:0 is not the correct approach in my opinion as it will mess up the content inside those divs.
Write
font-size:0;
. Like this:Check this http://jsfiddle.net/y7L7q/1/
OR
Write your mark like this:
Check this http://jsfiddle.net/y7L7q/2/