473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Making floats' widths grow with their content

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
2 1675
Banfa
9,065 Expert Mod 8TB
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
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

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

Similar topics

3
by: Lars G. Svensson | last post by:
As a regular ciwas reader, I learned that fixed-pixel designs are evil, so for the newly created site http://www.ddc-deutsch.de (in German, still very much under construction) I arranged the...
2
by: Stewart | last post by:
Originally posted in comp.lang.javascript: Newsgroups: comp.lang.javascript From: "Stewart" Date: 23 Aug 2005 02:50:04 -0700 Local: Tues, Aug 23 2005 10:50 am Subject: FireFox, RemoveChild,...
26
by: meltedown | last post by:
I have 2 left floating divs on a page. Sometime the left side is larger, sometimes the right side is larger. I want the page to have a margin at the bottom of whichever div is the largest. If I...
3
by: Joel Byrd | last post by:
I've got a 2-column tableless layout and I'm using floats to render the columns. Here are the basic style definitions for the 2 columns: #left_col { width: 59%; float: left; clear: left; }
1
by: davidr | last post by:
Hi, I am using Divs with CSS to setup a layout for a site. I am using the <Div>s and style sheets below. I want the TopMenu to go across the entire top of the browser. It does go across the...
4
by: Nathan Sokalski | last post by:
I have a <tdthat contains several elements, some of which are left-aligned, right-aligned, or centered. I do not know the widths of these elements beforehand, so I cannot give my <tda fixed width....
1
by: donpro | last post by:
https://testbed.odysseyshipping.com/index.php This is driving me nuts. I've spent much time trying to style this page footer but because I cannot set widths using "display: inline". I've tried...
5
by: Amir Michail | last post by:
Hi, I would like to center a logo between left and right floats with different widths. The issue is that the logo should be centered with respect to the window, not the area between the left...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.