Click here to get back home

clearing only local floats

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
clearing only local floats listerofsmeg01 11-11-2006
Posted by listerofsmeg01 on November 11, 2006, 11:22 am
Please log in for more thread options


I have the following code to align some form controls:
<style type="text/css">
.label {float:left; width:50%}
.input
</style>

<div>
<div class="label">Enter your username:</div>
<input type="text" name="username"/>
</div>

<div>
<div class="label">Enter your password:</div>
<input type="text" name="password"/>
</div>

This works fine until the font size is increased so that the label text
wraps onto a new line. This causes the next label to be floated NEXT to
the wrapped label, rather than underneath since there is now space next
to the new line, rather than is being occupied by the input box.

This is easily fixed by specifying "clear:both" in the .label css.

However, I now need an totally unrelated floated image to the left of
all this lot elsewhere on the page, and the clear is obviously pushing
the labels right down underneath this image

Is there any way to clear only LOCAL floats (ie in the same div)?

If not, then can someone suggest a different design to achieve the same
result (ie lined up inputs) without resorting to tables?

Many thanks.


Posted by Ben C on November 11, 2006, 12:41 pm
Please log in for more thread options


> I have the following code to align some form controls:
><style type="text/css">
> .label {float:left; width:50%}
> .input

Do you mean input, rather than .input?

></style>
>
><div>
> <div class="label">Enter your username:</div>
> <input type="text" name="username"/>
></div>
>
><div>
> <div class="label">Enter your password:</div>
> <input type="text" name="password"/>
></div>
>
> This works fine until the font size is increased so that the label text
> wraps onto a new line. This causes the next label to be floated NEXT to
> the wrapped label, rather than underneath since there is now space next
> to the new line, rather than is being occupied by the input box.
>
> This is easily fixed by specifying "clear:both" in the .label css.
>
> However, I now need an totally unrelated floated image to the left of
> all this lot elsewhere on the page, and the clear is obviously pushing
> the labels right down underneath this image
>
> Is there any way to clear only LOCAL floats (ie in the same div)?

No.

> If not, then can someone suggest a different design to achieve the same
> result (ie lined up inputs) without resorting to tables?

You can use absolute positioning. To cope with huge text sizes, I think
it's easiest to keep the .labels in the normal flow, but put the inputs
inside them and use the normal flow positions of the .labels as
reference points for positioning the inputs.

Like this:

<style>
.label
{
width: 50%;
position: relative; /* so it's a container for the input */
}
input
{
position: absolute;
left: 100%; /* 100% of container's width from left
of container-- i.e. sticking out on the
right */
top: 0;
}
</style>
</head>
<body>

<div>
<div class="label">Enter your username:
<input type="text" name="username"/>
</div>
</div>

<div>
<div class="label">Enter your password:
<input type="text" name="password"/>
</div>
</div>
</body>

Posted by Bergamot on November 11, 2006, 2:59 pm
Please log in for more thread options


listerofsmeg01@hotmail.com wrote:
>
> <div>
> <div class="label">Enter your username:</div>

Don't use div, use the label element. That's what it's for.

> <input type="text" name="username"/>
> </div>
>
> can someone suggest a different design to achieve the same
> result (ie lined up inputs) without resorting to tables?

Form fields (label/input pairs) are generally considered tabular data,
so use tables for this if you want.

--
Berg

Similar ThreadsPosted
Clearing floats without introducing a new line. How? August 18, 2005, 2:47 pm
Use local W3C validator on local site? September 17, 2005, 11:56 am
Playing a local mpeg file from a local HTML file... July 24, 2005, 6:02 pm
clearing out a May 3, 2005, 1:06 pm
selected clearing January 24, 2008, 11:36 am
Memory clearing and reload. January 23, 2005, 3:00 pm
Clearing floaters in Mozilla August 19, 2005, 6:03 pm
CSS Floats Images and IE (Help please!) September 4, 2005, 6:55 am
margins on cleared floats in Opera November 5, 2006, 11:34 am
in-client local src replace. Possible? April 9, 2005, 3:42 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap