HTML code:
<div id="container">
<div id="first">
foo bar baz foo bar baz
foo bar baz foo bar baz
</div>
<div id="second">
Foo
</div>
<div id="third">
foo bar baz foo bar baz
foo bar baz foo bar baz
</div>
</div>
CSS code:
body {
text-align: center;
}
#container {
display: inline-block;
background: lightcyan;
}
#first {
display: inline-block;
background: lightgreen;
}
#second {
background: orange;
}
#third {
width: 30%;
display: inline-block;
background: lightblue;
}
I am trying to ensure that the entire div#container shrink-wraps around div#first. The above code works as expected. See this demo: http://jsfiddle.net/HhrE6/
However, as I add more text into div#third, the shrink-wrap breaks. See the broken demo: http://jsfiddle.net/n4Kn2/
- Why does this happen?
- How can I prevent this from happening?