We Recommend

HTML: The Definitive Guide HTML: The Definitive Guide
They teach you that learning HTML is like learning any other language and that reading a book of rules can only take you so far. Readers begin writing what may be their first Web page just two pages into the book's second chapter. From there on, they provide a wide range of HTML coding to allow readers to learn from good examples. The book includes a handy "cheat sheet" of HTML codes for quick reference.


Posted By

maid450 on 09/12/07


Tagged

form css template html


Versions (?)


Who likes this?

7 people have marked this snippet as a favorite

maid450
robotoverlord
neuroasis
bbhack
vali29
brent-man
x-or


CSS Form Template


Published in: HTML 


an HTML template for form CSS styling


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4.  
  5. <title>A CSS-based Form Template</title>
  6.  
  7. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  8.  
  9. <style type="text/css">
  10.  
  11. /* General styles */
  12. body { margin: 0; padding: 0; font: 80%/1.5 Arial,Helvetica,sans-serif; color: #111; background-color: #FFF; }
  13. h2 { margin: 0px; padding: 10px; font-family: Georgia, "Times New Roman", Times, serif; font-size: 200%; font-weight: normal; color: #FFF; background-color: #CCC; border-bottom: #BBB 2px solid; }
  14. p#copyright { margin: 20px 10px; font-size: 90%; color: #999; }
  15.  
  16. /* Form styles */
  17. div.form-container { margin: 10px; padding: 5px; background-color: #FFF; border: #EEE 1px solid; }
  18.  
  19. p.legend { margin-bottom: 1em; }
  20. p.legend em { color: #C00; font-style: normal; }
  21.  
  22. div.errors { margin: 0 0 10px 0; padding: 5px 10px; border: #FC6 1px solid; background-color: #FFC; }
  23. div.errors p { margin: 0; }
  24. div.errors p em { color: #C00; font-style: normal; font-weight: bold; }
  25.  
  26. div.form-container form p { margin: 0; }
  27. div.form-container form p.note { margin-left: 170px; font-size: 90%; color: #333; }
  28. div.form-container form fieldset { margin: 10px 0; padding: 10px; border: #DDD 1px solid; }
  29. div.form-container form legend { font-weight: bold; color: #666; }
  30. div.form-container form fieldset div { padding: 0.25em 0; }
  31. div.form-container label,
  32. div.form-container span.label { margin-right: 10px; padding-right: 10px; width: 150px; display: block; float: left; text-align: right; position: relative; }
  33. div.form-container label.error,
  34. div.form-container span.error { color: #C00; }
  35. div.form-container label em,
  36. div.form-container span.label em { position: absolute; right: 0; font-size: 120%; font-style: normal; color: #C00; }
  37. div.form-container input.error { border-color: #C00; background-color: #FEF; }
  38. div.form-container input:focus,
  39. div.form-container input.error:focus,
  40. div.form-container textarea:focus { background-color: #FFC; border-color: #FC6; }
  41. div.form-container div.controlset label,
  42. div.form-container div.controlset input { display: inline; float: none; }
  43. div.form-container div.controlset div { margin-left: 170px; }
  44. div.form-container div.buttonrow { margin-left: 180px; }
  45.  
  46. </style>
  47.  
  48. </head>
  49.  
  50.  
  51. <div id="wrapper">
  52.  
  53. <h2>A CSS-based Form Template</h2>
  54.  
  55. <div class="form-container">
  56.  
  57. <p>More information about this template could be found in <a href="http://nidahas.com/2006/12/06/forms-markup-and-css-revisited/" title="Nidahas: Forms markup and CSS - Revisited">this blog article</a>.</p>
  58.  
  59. <div class="errors">
  60. <p><em>Oops... the following errors were encountered:</em></p>
  61.  
  62. <li>Username cannot be empty</li>
  63. <li>Country cannot be empty</li>
  64. </ul>
  65. <p>Data has <strong>not</strong> been saved.</p>
  66. </div>
  67.  
  68. <form action="#" method="post">
  69.  
  70. <p class="legend"><strong>Note:</strong> Required fields are marked with an asterisk (<em>*</em>)</p>
  71.  
  72. <legend>User Details</legend>
  73. <div><label for="uname" class="error">Username <em>*</em></label> <input id="uname" type="text" name="uname" value="" class="error" /></div>
  74.  
  75. <div><label for="email">Email Address </label> <input id="email" type="text" name="email" value="" />
  76. <p class="note">We will never sell or disclose your email address to anyone. <strong>This is an example of a note for an input field.</strong></p>
  77. </div>
  78.  
  79. <div><label for="fname">First Name <em>*</em></label> <input id="fname" type="text" name="fname" value="" size="50" /></div>
  80. <div><label for="lname">Last Name </label> <input id="lname" type="text" name="lname" value="" size="50" /></div>
  81.  
  82. </fieldset>
  83.  
  84. <legend>Contact Information</legend>
  85. <div><label for="address1">Address 1 <em>*</em></label> <input id="address1" type="text" size="50" /></div>
  86. <div><label for="address2">Address 2</label> <input id="address2" type="text" size="50" /></div>
  87. <div><label for="country" class="error">Country <em>*</em></label> <input id="country" type="text" name="country" value="" class="error" size="12" />
  88.  
  89. <p class="note">Errors could be highlighted by giving an <code>error</code> class to the input field, as seen here.</p>
  90. </div>
  91. <div><label for="telephone">Telephone</label> <input id="telephone" type="text" size="3" /> - <input type="text" size="3" /> - <input type="text" size="4" />
  92. <p class="note">(###) - ### - ####</p>
  93.  
  94. </div>
  95. </fieldset>
  96.  
  97. <legend>Submission</legend>
  98. <div><label for="year">Year (YYYY) <em>*</em></label> <input id="year" type="text" name="year" value="" size="4" maxlength="4" /></div>
  99. <div><label for="date">Month (MM)</label> <input id="date" type="text" name="date" value="" size="4" maxlength="2" /></div>
  100.  
  101. </fieldset>
  102.  
  103. <legend>Preferences</legend>
  104. <label for="type">Type <em>*</em></label>
  105. <select id="type">
  106. <optgroup label="Type of Whatever">
  107.  
  108. <option>Corporate</option>
  109. <option>Individual</option>
  110. </optgroup>
  111. </select>
  112. </div>
  113. <div class="controlset">
  114. <span class="label">User Status <em>*</em></span>
  115.  
  116. <input name="approved" id="approved" value="1" type="checkbox" /> <label for="approved">Approved</label>
  117. <input name="pending" id="pending" value="1" type="checkbox" /> <label for="pending">Pending Applications</label>
  118. <input name="actives" id="actives" value="1" type="checkbox" /> <label for="actives">Active Service</label>
  119. </div>
  120.  
  121. <div class="controlset">
  122. <span class="label">Preferred Location</span>
  123.  
  124. <input name="radio1" id="radio1" value="1" type="radio" /> <label for="radio1">Option 1</label>
  125. <input name="radio1" id="radio2" value="1" type="radio" /> <label for="radio2">Option 2</label>
  126. <input name="radio1" id="radio3" value="1" type="radio" /> <label for="radio3">Option 3</label>
  127. </div>
  128.  
  129. <div class="controlset">
  130. <span class="label">Something Else <em>*</em></span>
  131.  
  132. <input name="approved" id="check1" value="1" type="checkbox" /> <label for="check1">Some Option 1</label> <br />
  133. <input name="pending" id="check2" value="1" type="checkbox" /> <label for="check2">Some Option 2</label> <br />
  134. <input name="actives" id="check3" value="1" type="checkbox" /> <label for="check3">Some Option 3</label> <br />
  135.  
  136. </div>
  137. </div>
  138. </fieldset>
  139.  
  140. <legend>Profile</legend>
  141. <label for="desc">Description <em>*</em></label>
  142. <textarea id="desc" name="desc" cols="30" rows="4"></textarea>
  143.  
  144. </div>
  145. <label for="info">Additional Info </label>
  146. <textarea id="info" name="info" cols="40" rows="5"></textarea>
  147. </div>
  148. </fieldset>
  149.  
  150. <div class="buttonrow">
  151. <input type="submit" value="Save" class="button" />
  152.  
  153. <input type="button" value="Discard" class="button" />
  154. </div>
  155.  
  156. </form>
  157.  
  158. </div><!-- /form-container -->
  159.  
  160. <p id="copyright">Created by <a href="http://nidahas.com/">Prabhath Sirisena</a>. This stuff is in public domain.</p>
  161.  
  162. </div><!-- /wrapper -->
  163.  
  164. </body>
  165. </html>

Report this snippet 

You need to login to post a comment.