Web Standards
  Home arrow Web Standards arrow Page 3 - Forms
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WEB STANDARDS

Forms
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2005-03-09

    Table of Contents:
  • Forms
  • Method C: Simple and more accessible
  • Method D: Defining a form
  • Summary
  • Styling forms
  • No need to be redundant

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Forms - Method D: Defining a form


    (Page 3 of 6 )

      <form action="/path/to/script" id="thisform" method="post">
        <dl>
          <dt><label for="name">Name:</label></dt>
          <dd><input type="text" id"name" name="name" /></dd>
          <dt><label for="email">Email:</label></dt>
          <dd><input type="text" id="email" name="email"  /></dd>
          <dt><label for="remember">Remember this info?</label></dt>
          <dd><input type="checkbox" id="remember" name="remember" /></dd>
          <dt><input type="submit" value="submit" /></dt>
        </dl>
      </form>

    The last method we’ll look at in regards to form layout involves the use of a definition list to define label and form control pairs. It’s a somewhat controversial move—skirting the fringe of what a definition list is designed to do. But it’s also a method that’s gaining in widespread use, and one worthy of mentioning in this book.

    Further ahead, in Chapter 8, we’ll talk in more detail regarding definition lists—and the fact that they certainly are capable of more uses than most designers are aware of. Using a <dl> to mark up a form is a perfect example.

    You’ll notice in the code example that each form label is wrapped in a definition term tag (<dt>) followed by its associated form control wrapped in a definition description tag (<dd>). Doing this creates a pairing of label to form control, which when viewed in a browser without any style applied looks like Figure 5-6.


    Figure 5-6.  Default form layout using a definition list

    By default, most visual browsers indent the <dd> element on its own line. Fantastic. Without adding any additional <p> or <br /> tags,
    we have a readable form layout for those browsing without CSS.

    Defining style

    The simplest style we could add would be to easily remove the default indenting of <dd> elements within our form:

      form dd {
       margin: 0;
       }

    The preceding snippet of CSS would render our Method D example as viewed in Figure 5-7.


    Figure 5-7.  Definition list form example with <dd> margins removed

    The table-like format of Method A could also be achieved by floating <dt> elements within our form:

      form dd {
       margin: 0;
       }
      form dt{
       float: left;
       padding-right: 10px;
       }

    By floating the <dt> elements to the left, the form controls contained in <dd> tags will align themselves to the right, as seen in Figure 5-8. You’ll notice that the form controls don’t line up with each other perfectly—but at the very least this illustrates that while it’s possible to use a <dl> tag to lay out a form, the layout doesn’t have to put each element on its own line.

    In fact, because of the presence of the <dl>, <dt>, and <dd> elements—which are in addition to the form <label> and <input> elements—you’ll have plenty to work with in the way of elements that can be styled with CSS.


    Figure 5-8.   Form layout with floated <dt> elements

    This article is excerpted from Web Standards Solutions: The Markup and Style Handbook by Dan Cederholm (Apress, 2004; ISBN 1590593812). Check it out at your favorite bookstore today. Buy this book now.

    More Web Standards Articles
    More By Apress Publishing


     

    WEB STANDARDS ARTICLES

    - Completing a Configuration for Chrome and a ...
    - Getting Connected with Firefox and Chrome
    - Configuring Servers and Databases with Chrome
    - Configuring Firefox for Chrome and a Server
    - Designing the Elements of a Web Page
    - Matching div heights with CSS and JavaScript
    - Forms
    - Get Down With Markup
    - If I Said You Had a Beautiful Body...
    - Web Standards in Dreamweaver Part 3
    - Web Standards in Dreamweaver, Part 2
    - Web Forms
    - Making Lists Using XHTML
    - Web Standards in Dreamweaver, Part 1







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek