Home About Portfolio Links Contact

Table-less Forms using CSS

How to make a form with out using tables.

 

 
| More
Share with friends and family

 

About the CSS Script

If your a CSS freak like me you might have your own way of creating table-less structures, one of my favorites is creating table-less forms. In my example, I created a contact form which you will notice the name text floats to the left and the input field floats to the right. The way I go about this is first I create the outside wrapper by using <fieldset> which you can control the width in your CSS. Next lets define the caption to our field set by using <legend>, call it contact, and then create the form. To break up my fields into their own rows i'm going to use unordered list <ul> and use no list styling so we don't have any unwanted bullets. Inside each <li> were going to add our labels and input fields. By putting our text in the label tags we can safely float our text to the left and input fields to the right.

For example of how this looks Click Here...

 

CSS

  1. fieldset { padding: 0 10px; width: 400px;}
  2. legend { font-weight: bold; font-size: 20px;}
  3.  
  4. ul { margin: 0; padding: 0; list-style: none;}
  5. li { margin: 0; padding: 10px 0; clear: both;}
  6.  
  7. label { float:left; display:block; font-weight: bold; }
  8. input { float: right;}
  9. textarea { width: 99%; }
  10.  
  11. .clr { clear: both;}

 

HTML

  1. <legend>Contact:</legend>
  2. <form method="post" action="contact_demo.php" >
  3. <ul>
  4. <li><label for="name">Name: *</label>
  5. <input type="text" name="name" id="name" size="30" class="inputbox" value="<?=$name?>" /></li>
  6. <li><label for="email">Email: *</label>
  7. <input type="text" name="email" id="email" size="30" class="inputbox" value="<?=$email?>" /></li>
  8. <li><label for="comment">Comment: *</label></li>
  9. <li><textarea rows="4" cols="" name="comment" id="comment" ><?=$comment?></textarea></li>
  10. <li><input type="submit" name="submit" id="submit" value="submit" class="button" /></li>
  11. <li>&nbsp;</li>
  12. </ul>
  13. </form>

 

 

 

| More
Comments
AnonymousSumited: 03/18/2010
Juicy clothes Buy full line Juicy couture products from our site at a low price to make yourself a fashionista! Dress juicy couture clothing, holding juicy couture Shop prom dresses, formal dresses, prom shoes, 2010 designer prom gowns at dres4sale. for cocktail dresses, dresses for prom, homecoming dresses, and evening dresses. Cheap prom dresses or couture designer evening gowns for your next formal. evening dresses Evening Dresses. Women's Formal & Special Occasion Dresses ... Welcome to Cheap Evening Dresses for Sale! ... Buy Cheap Evening Dresses Sales & Accessories prom dresses
VeeraSumited: 11/01/2009
thanks for the code snippet! I've seen many people using tables for forms (including myself, when I started with CSS) but tables should be avoided for layout purposes. your code will be a great time saver!
Add Comment