Problem using float for forms

L

Leif K-Brooks

I'm using float in CSS to put form labels and descriptions to the left
of input boxes. To make the rows be rows, I have to use clear:both in
..formrow. The problem is, I'm also using float for a menu on the left of
the page, and I still want the input boxes next to the floating box. Is
there any way to make clear only apply to the label and description?

An example is at http://ecritters.biz/floatproblem.html.
 
M

Mark Parnell

Leif said:
I'm using float in CSS to put form labels and descriptions to the left
of input boxes. To make the rows be rows, I have to use clear:both in
.formrow. The problem is, I'm also using float for a menu on the left
of the page, and I still want the input boxes next to the floating
box. Is there any way to make clear only apply to the label and
description?

An example is at http://ecritters.biz/floatproblem.html.

Add #afterfloated {padding-left: 11%;} or similar.

HTH
 
R

Richard

Leif K-Brooks wrote:>>
I'm using float in CSS to put form labels and descriptions to the left
of input boxes. To make the rows be rows, I have to use clear:both in
.formrow. The problem is, I'm also using float for a menu on the left of
the page, and I still want the input boxes next to the floating box. Is
there any way to make clear only apply to the label and description?

The values for "clear" are "none; left; right; both".
Try one and see which works.
 
S

SteW

Leif said:
I'm using float in CSS to put form labels and descriptions to the left
of input boxes. To make the rows be rows, I have to use clear:both in
.formrow. The problem is, I'm also using float for a menu on the left of
the page, and I still want the input boxes next to the floating box. Is
there any way to make clear only apply to the label and description?

An example is at http://ecritters.biz/floatproblem.html.
Is this something like what you want?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head>
<title>Float problem</title>
<style type="text/css">
.inline{display: inline;}
p.example{float: left; background: black; color: white; width: 10em;}
.foo{margin-left: 12em;}
</style>
</head>
<body>
<p class="example">This is a floated <code>&lt;div&gt;</code>
element. It has no real purpose, and is simply an example.</p>
<form action="#" method="get" class="foo">
<label for="input1" class="inline">Input 1</label>
<input type="text" id="input1" name="input1" />
<p>Text box for the purpose of demonstration</p>
<label for="input1" class="inline">Input 2</label>
<input type="text" id="input2" name="input2" />
<p>Text box for the purpose of demonstration</p>
</form>
</body>
</html>

Ste W
 
B

boclair

Leif K-Brooks said:
I'm using float in CSS to put form labels and descriptions to the left
of input boxes. To make the rows be rows, I have to use clear:both in
.formrow. The problem is, I'm also using float for a menu on the left of
the page, and I still want the input boxes next to the floating box. Is
there any way to make clear only apply to the label and description?

An example is at http://ecritters.biz/floatproblem.html.

I cannot see a reason to float the labels to the left. label is a inline
element and will flow naturally to the left as [label element][input
element]

Would something like this do as well

<div class="formlabel">
<label for="input1">Input 1</label></div>
<div class="formdesc"><label for="input1 data">Text box for the purpose of
demonstration.</label><span class="formwidget"><input type="text"
id="input1" name="input1" /></span>
</div>

Louise
 
S

SteW

SteW wrote:

That doesn't validate, partly due to xhtml <input /> instead of html
<input>, partly due to inputs/labels not being in a block element. Try
this validated version - it even looks better :)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head>
<title>Float problem</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.inline{display: inline;}
p.example{float: left; background: black; color: white; width: 10em;}
.foo{margin-left:12em;}
</style>
</head>
<body>
<p class="example">This is a floated <code>&lt;div&gt;</code>
element. It has no real purpose, and is simply an example.</p>
<form action="#" method="get" class="foo">
<p><label for="input1" class="inline">Input 1</label>
<input type="text" id="input1" name="input1"><br>
Text box for the purpose of demonstration</p>
<p><label for="input2" class="inline">Input 2</label>
<input type="text" id="input2" name="input2"><br>
Text box for the purpose of demonstration</p>
</form>
</body>
</html>
 
L

Leif K-Brooks

boclair said:
I cannot see a reason to float the labels to the left. label is a inline
element and will flow naturally to the left as [label element][input
element]

I also want descriptions on the left of the input boxes.
 
L

Leif K-Brooks

Richard said:
The values for "clear" are "none; left; right; both".
Try one and see which works.
None work, because the description and label are on the same side as the
floating box I don't want cleared.
 
S

SteW

Leif said:
SteW said:
like this?

input1 [text box]
description

or like this
input1 description [text box]


More like this:
input1 [text box]
description

That is basically the layout given by my examples posted this^H^H^H^H
yesterday morning.
See it here: http://www.mastercooper.co.uk/float.html
Adjust the spacing between label and text box with
.foo input{margin-left:12em;}

The markup:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head>
<title>Float problem</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
p.example{float: left; background-color: black; color: white;
width: 10em;}
.foo{margin-left:12em;}
.foo input{margin-left:12em;}
.no_margin{margin-left:0;}
</style>
</head>
<body>
<p class="example">This is a floated <code>&lt;div&gt;</code>
element. It has no real purpose, and is simply an example.</p>
<form action="#" method="get" class="foo">
<p><label for="input1" class="inline">Input 1</label>
<input type="text" id="input1" name="input1"><br>
Text box for the purpose of demonstration</p>
<p><label for="input2" class="inline">Input 2</label>
<input type="text" id="input2" name="input2"><br>
Text box for the purpose of demonstration</p>
<button type="submit" class="no_margin">send</button>
</form>
</body>
</html>

Ste W
 
R

rf

Mark Parnell said:
Both brucie and Richard are back. Everything will return to normal shortly.
:)

Using the word "normal" in a post to alt.html is surely an oxymoron :)

Cheers
Richard.
 
M

Mark Parnell

rf said:
Using the word "normal" in a post to alt.html is surely an oxymoron
:)

"Normal" is a cycle on a washing machine.

I meant normal for alt.html, which of course would be abnormal anywhere else
(except maybe alt.html.critique ;-) ).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top