By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Making floats' widths grow with their content

P: 1
Hi All,

Two questions:

1. Is it possible to make a floated div grow in width with its contents?

I've been searching on the web for a way to make the width of a float grow with the width of its content, without success. There's loads of information about how to do this with heights, but I can't find anything that works for widths.

Is it possible?

2. How do you centre a floated element?

Thanks in advance,

Andrew
Sep 29 '06 #1
Share this Question
Share on Google+
2 Replies


Banfa
Expert Mod 5K+
P: 8,916
1. I don't think that it is very easily possible. The best you can do is use Javascript to determine the width of the content and then re-write the width of the float. However some context would be of use in this question.

2. You can't centre floats, it doesn't make logical sense. A float is float left or float right, i.e. you request that the float appears at the left hand margin and that other content flows past it on the right or vice versa.

An element can not be on the left and in the centre at the same time.
Sep 29 '06 #2

marty
P: 4
I don't know how to make the width of a float grow with the content (but it's easy with tables, why don't you use a table, ha ha, no, we don't do that any more).

Centering a float is supposed to be automatic if you specify the left and right margins to be "auto." I'm told that MSIE won't recognize that unless the element that contains the float has "text-align: center" because MSIE treats contained elements as text. Of course, then any text you don't want to be centered has to have its own container with "text-align" specified.
Sep 29 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.