I am trying to arrange several elements in a row so that they all match the width of the container. To prevent word wrapping, I added the parent element "white-space: nowrap" and added the children "white-space: normal" so that they could wrap the text (optional).
The problem is that with this configuration, the right most of the children sometimes exceed the width of the parent.

HTML:
<div id="container"> <div class="child"> child 1 </div> <div class="child"> child 2 text that might be long enough to wrap, but still exceed the parent </div> </div>
CSS
#container { white-space: nowrap; width: 200px; background: yellow; border: 1px solid brown; padding: 5px; } .child { display: inline-block; border: 2px solid red; vertical-align: top; white-space: normal; }
http://jsfiddle.net/7e5TU/1/ (change the length of the text if the problem does not appear immediately).
I know that I can solve it using a table and possibly with a float on the left and on the right โoverflow: hiddenโ, but I see no reason why this should not work.
Can anyone give some ideas? I basically would like to understand that in the box, the model causes this behavior. Thanks!
source share