Web Standards
  Home arrow Web Standards arrow Page 2 - Web 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

Web Forms
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 45
    2004-08-23

    Table of Contents:
  • Web Forms
  • Method B: Tableless, but Cramped
  • The label E
  • Defining Style
  • tabindex Attribute
  • Styling Forms
  • Using label
  • Use fieldset to Group Form Sections
  • Three-dimensional legend

  • 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


     
    Method B: Tableless, but Cramped

    FONT face="courier new, courier, mono" size=2><form action="/path/to/script" method="post">
     <p>
      Name: <input type="text" name="name" /><br />
      Email: <input type="text" name="email" /><br />
      <input type="submit" value="submit" />
     </p>
    </form>
     

    Using a single paragraph and a few <br/> tags to separate the items is a passable solution—but could visually render a bit on the cramped side. Figure 5-2 shows how this would typically appear in a browser.

    cederholm 

    Figure 5-2. Method B as rendered in a browser

    You can see that while we got away without using a table, it looks rather cramped and ugly. We also run into the problem of the form controls not lining up perfectly, as seen in Figure 5-2.

    We could alleviate some of the crowdedness by adding some margins to the <input> elements using CSS like this:

    input {
    margin: 6px 0;
    }

    The preceding would add a 6-pixel margin to both the top and bottom of each <input> element (the name, e-mail, and submit controls), spacing out the elements as seen in Figure 5-3.

    cederholm 
     
    Figure 5-3. Method B with padding added to the input elements

    While there’s nothing particularly wrong with Method B, there are a few adjustments we can make to build a better form. And those adjustments are evident in Method C. So let’s take a look.

    Method C: Simple and more accessible
     
    <form action="/path/to/script" id="thisform" method="post">   <p><label for="name">Name:</label><br />
      <input type="text" id="name" name="name" /></p>
      <p><label for="email">Email:</label><br />
      <input type="text" id="email" name="email" /></p>
     <p><input type="submit" value="submit" /></p>
    </form>

    I like Method C for several reasons. First off, for a simple form like this example, I find it convenient to contain each label and control in its own paragraph. When viewed unstyled, the default spacing of a paragraph should be enough to set the items apart in a readable way. Later, we could control precise spacing with CSS on <P> tags that are contained within our form.

    We’ve even gone a step further and have given this form a unique, but boring, id="thisform". So, that precise spacing I was just referring to could go something like this:

    #thisform p {
      margin: 6px 0;
       }

    Essentially, we’re saying that all <P> tags within this particular form should have top and bottom margins of 6 pixels—overriding the default margins that the browser imposes on paragraphs in the absence of any styling.

    Another difference that Method C has over the previous two is that while each group (label and field) are wrapped in <P> tags, a <br/>
    puts each on its own line. Using a <br/> to separate the items gets around the issue of fields not lining up perfectly due to text labels of different lengths.

    Figure 5-4 shows how Method C would appear in a visual browser, with the CSS applied to each <P> tag as mentioned earlier.

     
    cederholm 

    Figure 5-4. Method C as viewed in a browser, with CSS applied to <P> tags

    Aside from the visual aspects of Method C, let’s take a look at the most important advantages it has: in particular, an accessibility improvement.

    This chapter is 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


       · It is a very good tutorial, very didactical. It is presented in intuitive and clear...
     

    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