Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / CSS / January 2008



Tip: Looking for answers? Try searching our database.

Form should use space efficiently

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
k3pp0 - 27 Jan 2008 22:44 GMT
Hello,

let's say I have this simple HTML form:

<form method="post" action="foo.php">
    <p>
        <label for="username">Username:</label>
        <input type="text" name="username" />
    </p>
    <p>
        <label for="password1">Password:</label>
        <input type="password" name="password1" />
    </p>
    <p>
        <label for="password2">Password again:</label>
        <input type="password" name="password2" />
    </p>
    <p>
        <label for="email">E-Mail:</label>
        <input type="text" name="email" />
    </p>
    <p>
        <input type="submit" name="register" value="Register" />
    </p>
</form>

I want all the <label>s to have the same width, so the labels and
inputs line up nicely.
For exmaple: label { width: 200px; }.

Now I want all the <input>s to fit the rest of the width of the
browser window. So if you resize the window, the input fields fill out
the space between the "right border of the <label>" and the "right
border of the browser window" automatically. You could say: <label> +
<input> = 100% of the window's width.

I'm hoping for a solution completely in CSS, I hope you guys
understand my problem and can help me.

Thanks in advance!
Harlan Messinger - 28 Jan 2008 01:12 GMT
> Hello,
>
[quoted text clipped - 34 lines]
> I'm hoping for a solution completely in CSS, I hope you guys
> understand my problem and can help me.

This is one case where it's legitimate to use a table, assuming that was
the concern behind your wanting to do this completely in CSS. You have a
bona fide two-dimensional array where the rows are different items and
the columns are, for each one, a label and an input field.
Jukka K. Korpela - 28 Jan 2008 05:35 GMT
Scripsit k3pp0:

> I want all the <label>s to have the same width, so the labels and
> inputs line up nicely.

There's not much reason not to use a table. A table may cause problems
to some speech-based browsers that cannot then associate labels with
input fields, but using <label> markup mostly handles this. Note,
however, that your markup needs a fix:

<label for="username">Username:</label>
<input type="text" name="username" />

The for="..." attribute needs to refer to an element by its id="..."
attribute, so you need to add it:
<input type="text" name="username" id="username" />

You _can_, however, use CSS instead of a table. The simplest way is
probably to make the <label> elements floated; for an example, see
http://www.cs.tut.fi/~jkorpela/forms/tables.html#css

> For exmaple: label { width: 200px; }.

Oh no. What would that cause when the user changes font size to, say,
60px?

Use the em, Luke.

And using a table is even more flexible, since you don't need to make
any guess on the width. Of course it would be nice to do the same in
CSS, but for that, we would need (surprise!) the tabular presentation
properties, such as display: table and all that, which isn't supported
by IE even in IE 7.

> Now I want all the <input>s to fit the rest of the width of the
> browser window. So if you resize the window, the input fields fill out
> the space between the "right border of the <label>" and the "right
> border of the browser window" automatically. You could say: <label> +
> <input> = 100% of the window's width.

Using table markup, you would set the table width to 100% (in HTML or in
CSS) and the width of the <input> elements to 100% (in CSS).

Using just CSS, I'm afraid there's no way at present.

Signature

Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.