469,306 Members | 2,531 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Can a div's width expand to fit content's width?


I've created a banner with a drop-shadow using a div - there's a mock-
up at http://tinyurl.com/6n7czu . The only problem is that the way
I've done it, I have to specify the width of the div - if I don't, it
renders with a width of 100%. Is there any way of making the width fit
the text it encloses (plus padding), and so that it expand
automatically if you add more text?

Apr 8 '08
50 6903
On Apr 10, 8:35 pm, Dave Rado <dave.r...@dsl.pipex.comwrote:
Floats don't meet my requirement for reasons discussed earlier in the
thread (the boxes have to be shrink-to-fit *and* centred). I've got it
working using tables though.
AFIAK you cannot reliably do it by CSS alone because of different
quirks on different browsers. It also very difficult to do because of
official by very silly treatment of overflow:auto. It is being taken
as kind of overflow:remainder, so "take all space what rest" while it
should be, as the name implies, "take exactly how much space you need
to accommodate the current content but not a pixel more".

I would stay with one cell table to keep things cross-browser
compatible and reliable.
Jun 27 '08 #51

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bob Imperial | last post: by
3 posts views Thread by Kai Rosenthal | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.