Forum Moderators: not2easy

Message Too Old, No Replies

Div width

How to get div width to adjust

         

louis

5:18 am on Jan 4, 2008 (gmt 0)

10+ Year Member



Hello. First post here.

Easy question. How do I make a div's width adjust to what is inside. If I leave the width blank, IE7 makes it 100%. I need it to adjust to whatever is inside the div which in this case is a submit button. I don't want to set it manually because I use the style for other things that are different widths.

Thanks,
Louis

Xapti

6:09 am on Jan 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Divs are by default block level elements. Block level elements expand to maximum width by default, and take up the entire horizontal space regardless of width.
If you want it to not take up all horizontal space (regardless of it's width), you should float the element.

Well generally you just need to float it to "shrinkwrap" it, but it's not officially legal to float something without specifying a width.

Perhaps the biggest question is why do you need this div there?
Would it not be possible to just use a span instead?

louis

6:15 am on Jan 4, 2008 (gmt 0)

10+ Year Member



Oooh I see. Thanks man. I used span instead and it worked.

Thanks heaps.