Div smart width

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2012-06-22T20:51:42Z Indexed on 2012/06/22 21:16 UTC
Read the original article Hit count: 147

Filed under:
|

see fiddle

html

<div class="e" style="left:5px;top:5px;">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbb</div>

<div class="e" style="left:5px;top:100px;">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>?

css

.e {
    font-size: 10px;
    font-family: arial;
    background-color: yellow;
    position: absolute;
    max-width: 300px;
}

you will notice the 2nd div fits the size of the content exactly, but on the first div there's a bunch of empty space to the right of the a's and b's. This is because the div hit its max width of 300px and then wrapped the b's to a 2nd line. The wrapping is good, but then I would expect the div to then shrink back down to the width of the a's so that there's no empty space to the right.

Is it possible to get it to do this?

Tested in Chrome and FF. ?

© Stack Overflow or respective owner

Related posts about html

Related posts about css