Topic: Multi-Column Forms Best Practice (Page 1 of 1) |
|
---|---|
Maniac (V) Mad Scientist From: Rochester, New York, USA |
posted 07-26-2007 19:20
I work with an application that has a few hundred different complex forms. I often find myself in a situation requiring the following layout: code: <form> <table> <tr> <th><label>Label 1</label></th> <td><input type="text"/></td> <th><label>Label 2</label></th> <td><input type="text"/></td> </tr> ... repeate another 20 times ... </table> </form>
code: <style type="text/css"> label { display: block; float: left; width: 15% } span { display: block; float: left; width: 35%;} span input { width: 100%; } </style> <form> <div> <label>Label 1</label> <span><input type="text"/></span> <label>Label 2</label> <span><input type="text"/></span> </div> <div> ... repeate another 20 times ... </div> </form>
|
Paranoid (IV) Inmate From: Norway |
posted 07-26-2007 19:34 |
Paranoid (IV) Inmate From: Florida |
posted 07-26-2007 20:54
code: <label>Label 1 <input></label>
|
Maniac (V) Mad Scientist From: Rochester, New York, USA |
posted 07-26-2007 22:11
I like the fieldset idea. That makes things better but I do need to <span> element as I might have a complex widget such as code: <span><input type="text"/><input type="button" value="..."/></span>
code: <span><input type="text" id="month"/><input type="text" id="day"/><input type="text" id="year"/></span>
code: <style type="text/css"> label { display: block; width: 50%; float: left; } </style> <form> <fieldset> <label>Label 1 <input type="text"/><input type="text"/><input type="text"/></label> <label>Label 2 <input type="text"/></label> </fieldset> <fieldset> <label>Another Label 3 <input type="text"/></label> <label>Another Label 4 <input type="text"/><input type="button" value="..."/></label> </fieldset> </form>
code: <style type="text/css"> label { display: block; width: 50%; float: left; } label span { display: block; width: 25%; float: left; } </style> <form> <fieldset> <label> <span>Label 1</span> <input type="text"/> <input type="text"/> <input type="text"/> </label> <label> <span>Label 2</span> <input type="text"/> </label> </fieldset> <fieldset> <label> <span>Another Label 3</span> <input type="text"/> </label> <label> <span>Another Label 4</span> <input type="text"/> <input type="button" value="..."/> </label> </fieldset> </form>
|
Lunatic (VI) Inmate From: under the bed |
posted 07-26-2007 22:30
1) A <label> wrapped with a <th> is redundant code: <form> <fieldset> <label>Label 1 <input type="text"/><input type="text"/><input type="text"/></label> <label>Label 2 <input type="text"/></label> </fieldset> <fieldset> <label>Another Label 3 <input type="text"/></label> <label>Another Label 4 <input type="text"/><input type="button" value="..."/></label> </fieldset> </form>
code: <form> <fieldset> <legend>Heading 1</legend> <label for="input1">Label 1</label><input id="input1" type="text"/> <label for="input2">Label 2</label><input id="input2" type="text"/> <label for="input3">Label 3</label><input id="input3" type="text"/> <label for="input4">Label 4</label><input id="input4" type="text"/> </fieldset> <fieldset> <legend>Heading 2</legend> <label for="input5">Another Label 5</label><input id="input5 type="text"/> <label for="input6">Another Label 6</label><input id="input6 type="text"/> <input type="button" value="..."/> </fieldset> </form>
|
Paranoid (IV) Inmate From: Norway |
posted 07-26-2007 23:25
The SPAN is not necessary either. You can easily handle multiple inputs using CSS to move the inputs away and position the label in the top left part of a group of inputs: code: <?xml version='1.0' encoding='iso-8859-1'?> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' > <head> <title>te | Mathieu 'P01' HENRI | 20070726</title> <style type='text/css'> form { background:pink; padding:1em; margin:1em; } fieldset { position:relative; background:orange; padding:1.5em 0 0 33%; margin:1em 0; border:0; } fieldset legend { display:block; font-weight:bold; background:red; position:absolute; left:0; right:0; top:0; width:100%; height:1.5em; padding:0; } fieldset label { position:relative; } br { clear:both; } fieldset label { position:absolute; left:0; right:70%; display:block; background:yellow; } </style> </head> <body> <form action=''> <fieldset> <legend>part 1</legend> <label for='input1'>input1's label</label> <textarea id='input1'> ata tetete dgsd! </textarea> <br/> <label for='input3'>input3's label</label> <input id='input3' type='text' /> <input id='input4' type='text' /> <input id='input5' type='text' /> </fieldset> <fieldset> <legend>part 2</legend> <label for='input6'>input6's label</label> <input id='input6' type='text' /> <input id='input7' type='text' /> <input id='input8' type='text' /> <input id='input9' type='checkbox' /> <br/> <label for='input10'>input10's label</label> <input id='input10' type='radio' /> <input id='input10' type='radio' /> <input id='input10' type='radio' /> <input id='input10' type='radio' /> <br/> <label for='input11'>select11's label</label> <select id='input11' height='3'> <option>opt 1<option> <option>opt 2<option> <option>opt 3<option> <option>opt 4<option> <option>opt 5<option> </select> </fieldset> </form> </body> </html> |
Paranoid (IV) Inmate From: Norway |
posted 07-26-2007 23:32 |