<cfwhat>

Friday, November 11, 2005

CSS form layout

For a while now I've been looking for a CSS solution for laying out forms. Yesterday I was playing around
and tried using absolute positioning. This seems to work quite well across several browser/platform combinations.
I'll have to test it on more browsers but for now I'm happy. Here's an example:
















Under 20

21 -30

31 -40

Over 40







<style type="text/css">
label {
position: absolute;
width: 95px;
text-align: right;
font-weight: bold;
}
input, textarea, select {
margin-left: 100px;
}
</style>


<form action="index.cfm" method="post">

<label for="name">Name:</label>
<input type="text" name="name" size="30" maxlength="100"><br />

<label for="gender">Gender:</label>
<select name="gender">
<option value=""></option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select><br />

<label for="AgeGroup">Age group:</label>
<input type="radio" name="AgeGroup" value="1">Under 20 <br />
<input type="radio" name="AgeGroup" value="2">21 -30<br />
<input type="radio" name="AgeGroup" value="3">31 -40<br />
<input type="radio" name="AgeGroup" value="4">Over 40<br />

<label for="address">Address:</label>
<textarea cols="50" rows="5" name="address"></textarea>
</form>

0 Comments:

Post a Comment

<< Home