Correction
Do not mix, hug the table!
"Fixes" it on Firefox (checked 31.2.0) and IE 8 and honestly more semantically correct.
.a{ display:inline-table; max-width:45%; } .b{ display:table-cell; padding-right:5px;} .c{ display:table-cell; }
<span class="a"> <span class="b">b</span> <span class="c">c1 c2</span> </span> <br /><hr /><br /> <span class="a"> <span class="b">longer</span> <span class="c">Bacon ipsum dolor amet excepteur laboris irure, corned beef minim pastrami venison in anim incididunt strip steak ea non doner.</span> </span>
Why a problem occurred
The problem with your source code is that Firefox takes the floating-point element completely out of the stream when calculating the size of the compressible matrix. While float affect the width of the contents of the stream, they themselves are not in the stream and therefore simply take horizontal space from the rest of the content, causing the behavior you saw
Here is a demonstration of what is happening (view in Firefox to see it). Note that outline used on .a and .c , but a thick border (which actually occupies a space) is used on .b .
.a { display: inline-block; outline: 1px solid blue; } .b { float: left; border: 5px solid green; } .c { display: table; outline: 1px solid red; }
<span class="a"> <span class="b">b</span> <span class="c">c1 c2</span> </span> <br /> <span class="c">c1 c2</span>
This is by design, and not an error and checking the current specification , the basic working model of the box, and the specification for calculating the width , you will see that the floats are marked out-of-flow and the specification of block formatting and inline formatting clearly indicates that the float are part of the inline-context width , but does not for block context (inside inline-block ). Thus, Firefox actually behaves in accordance with a strict interpretation of the specification - this is technically a bug in other browsers.
However, there is still a problem with how Firefox does this.
If we make the float larger than our streaming content (and go back to the borders, since the paths include overflowing children, I moved the remaining brother to the left by 1px so that it aligns with my nephew) (again, view in Firefox)
.a { display: inline-block; border: 1px solid blue; } .b { float: left; border: 5px solid green; width:200px; } .c { display: table; border: 1px solid red; } .d { position:relative; left:1px; } .e { max-width:100px; }
<span class="a"> <span class="b">b</span> <span class="c">c1 c2</span> </span> <br /> <span class="cd">c1 c2</span> <br /> ^^^ without <em>.a</em> having a width limit <hr /> vvv with <em>.a</em> having a width limit <br /> <span class="ae"> <span class="b">b</span> <span class="c">c1 c2</span> </span> <br /> <span class="cd">c1 c2</span>
The blue box is stretched to contain all of its green child, although, according to a strict interpretation of the specification , it is assumed that it is overflowing. This is a bug with Firefox, since floats should only affect the parent width:auto in the embedded context. In the context of the block, which is supposed to be inside the inline-block , the width of the floats is not included.
Note that just like most other browsers (to some extent, Firefox will increase the size of the parent to the width of the float window, while other browsers will put the incoming stream next to it if the parent can still grow) and if you specify any values ββor width limits for .a (ala .e in my example), you will get the expected behavior (as shown) of the green fleet overflowing its parent element (should be in all browser cases, since all of these behavioral issues are based on width:auto ).
Loans
A lot of Oriol beer (poster of another answer) - if I did not argue with him about this, I would have no reason to really delve into the specifications and find out what is really happening. He also credited him for pointing out that Firefox still hadn't completed it - that was all he liked.