Reputation: 6499
I am referring to this Fiddle I found on SO that uses display: inline-block;
and I have applied it to my own work but I can't figure out how to get the two divs to sit flush side by side, not with the 3-4px gap?
I've tried:
html
<div class="container">
<div class="left">
LEFT
</div>
<div class="right">
RIGHT
</div>
</div>
css
div.left {
background:blue;
height:200px;
width:300px;
}
div.right{
background:green;
height:300px;
width:100px;
}
.container{
background:black;
height:400px;
width:450px;
}
.container div {
display: inline-block;
}
But got nothing.
Upvotes: 1
Views: 5252
Reputation: 3765
Actually you dont have to change anything in css to avoid the gap,
this is a whitespace problem in HTML,
change the html to this
<div class="container">
<div class="left">LEFT
</div><div class="right">RIGHT
</div>
</div>
OR
you can edit your css
You can use float:left;
instead of display:inline-block;
to nullify the whitespace problem.
Upvotes: 2
Reputation: 3802
Rather using display:inline-block
you can float
the div's
,just change the css
to
.container div {
float:left;
}
The above code should get the required result.It will align the div
right next to each other without any space.
Refer the links below to see what caused the white space or about float
and display:inline block
Upvotes: 0
Reputation: 3065
Use 2 span's (now divs), make the inline-block and don't leave any spaces or new lines between them. Use spans not divs because some old ies can't make inline-block elements from default block elements like divs.
Like this:
<span style="display: inline-block">one</span><span style="display: inline-block">two</span>
Not like this:
<span style="display: inline-block">one</span> <span style="display: inline-block">two</span>
Upvotes: 1
Reputation: 894
I would use float:left
but also try setting margins on div.left and div.right to 0 like:
margin:0 auto;
So, with your fiddle:
div.left {
background:blue;
height:200px;
width:300px;
margin:0 auto;
float:left;
}
Upvotes: 2
Reputation: 85545
If you set display: inline-block; then add margin-right: -4px;
to remove the gap.
Upvotes: 1