Reputation: 763
As shown in the example, the two of 150px div
s won't stay in the 300px parent div even if I set them as inline-block
s.
Why would they occupy extra space?
There is no problem when using float:left
.
http://jsfiddle.net/r2LLzwbu/1/
Upvotes: 1
Views: 191
Reputation: 3429
you can do this :
.inner-1{
background:green;
width:150px;
height:100px;
margin:0;border:0;padding:0;
}
Remove .inner-1
css display:inline-block;
Upvotes: 0
Reputation: 726
Chris Coyier explains this very well in one of his post here -
Fighting the Space Between Inline Block Elements
To summarize what Chris said -
The inline blocks are similar to independent words in a sentence. Inline-block carries the space in between them the way words do in a sentence.
Upvotes: 1
Reputation: 368
The problem is the indentation causes extra spaces to appear in the div. To illustrate, if you change the HTML to a single line:
<div class="outer"><div class="inner-1"></div><div class="inner-2"></div></div>
it works. Updated Fiddle.
Upvotes: 1