New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

Web Accessibility Principles
Illustration by

Aligning labels and fields using CSS


From:

Web Accessibility Principles

with Zoe Gillenwater

Video: Aligning labels and fields using CSS

>> In the previous movie we began cleaning up the form's appearance in CSS, but there are still some improvements that we can make to the alignment of the labels and their fields. Remember that we floated the items in the mainNAV bar to get them to line up nicely side by side. We'll use a similar technique here. We'll float the label elements so that they'll align better with their matching fields. If you're following along with the exercise files, the page we're working on is named departments.html and can be found in the 08_06 folder of the chapter eight exercise files.
Expand all | Collapse all
  1. 2m 0s
    1. Welcome
      1m 3s
    2. Using the exercise files
      57s
  2. 33m 15s
    1. What does accessibility mean?
      5m 51s
    2. How does accessibility help your users?
      3m 30s
    3. Experiencing a website via a screen reader
      5m 46s
    4. How does accessibility help you and your clients?
      3m 9s
    5. Overview of Section 508 standards
      5m 51s
    6. Overview of WCAG standards
      6m 4s
    7. Understanding consistency and semantic markup
      3m 4s
  3. 54m 31s
    1. Understanding screen readers and accessibility tools
      6m 12s
    2. Getting accessible browsers
      5m 41s
    3. Customizing Firefox for accessibility testing
      5m 53s
    4. Using custom accessibility toolbars
      5m 28s
    5. Using Fangs and the Color Contrast Analyzer
      5m 30s
    6. Accessibility tools to bookmark
      5m 53s
    7. Using automated accessibility checking tools
      4m 57s
    8. Setting up the JAWS screen reader on Windows
      6m 42s
    9. Using the VoiceOver screen reader on Mac OS X
      5m 52s
    10. Setting Dreamweaver accessibility preferences
      2m 23s
  4. 26m 12s
    1. Avoiding tables for layout
      3m 30s
    2. Using CSS for layout
      2m 40s
    3. Creating a fixed-width layout
      5m 51s
    4. Creating an elastic layout
      3m 51s
    5. Creating a liquid layout
      3m 4s
    6. Customizing a liquid layout
      7m 16s
  5. 1h 6m
    1. Specifying the language
      3m 43s
    2. Setting page titles
      2m 16s
    3. Setting headings and paragraphs
      9m 55s
    4. Styling headings
      9m 56s
    5. Hiding section headings from sighted users
      6m 41s
    6. Styling text for readability
      6m 41s
    7. Ensuring proper color contrast
      6m 36s
    8. Creating text emphasis
      4m 29s
    9. Indicating quotations
      4m 29s
    10. Creating basic lists
      4m 16s
    11. Styling lists
      7m 15s
  6. 1h 15m
    1. Using lists for navigation
      6m 45s
    2. Creating a horizontal navigation bar
      13m 25s
    3. Creating a vertical navigation bar
      11m 44s
    4. Adding skip navigation links
      12m 0s
    5. Hiding skip navigation links
      6m 17s
    6. Proper link text and title attributes
      6m 11s
    7. Opening new windows
      4m 28s
    8. Accessibility limitations of fly-out menus
      6m 30s
    9. Creating an accessible fly-out menu
      8m 38s
  7. 27m 55s
    1. Proper ALT text for navigation images
      4m 57s
    2. Proper ALT text for decorative images
      5m 19s
    3. Adding ALT text to an existing site
      6m 9s
    4. Adding ALT text to image maps
      5m 58s
    5. Describing complex graphics
      5m 32s
  8. 34m 1s
    1. Using tables for data
      3m 0s
    2. Creating header cells
      4m 5s
    3. Adding table captions and summaries
      9m 9s
    4. Styling tables
      5m 19s
    5. Applying header cells to complex tables
      6m 52s
    6. Adding id and headers attributes
      5m 36s
  9. 42m 7s
    1. Understanding form accessibility issues
      3m 7s
    2. Labeling form fields
      6m 9s
    3. Adding fieldsets and legends
      4m 42s
    4. Moving forms out of tables
      3m 44s
    5. Cleaning up a form's appearance
      4m 53s
    6. Aligning labels and fields using CSS
      9m 39s
    7. Indicating required fields
      6m 15s
    8. Dealing with CAPTCHA
      3m 38s
  10. 7m 29s
    1. The Text-Only technique
      3m 21s
    2. The Access Keys technique
      2m 35s
    3. The Tab Index technique
      1m 33s
  11. 18s
    1. Goodbye
      18s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
Web Accessibility Principles
6h 10m Appropriate for all Oct 16, 2007

Viewers: in countries Watching now:

Accessibility on the web has been an issue for over a decade, and it remains a crucial--but often overlooked--element of web design. Instructor Zoe Gillenwater explains the concept of accessibility as it applies to the web, and describes how it affects the audience. She also covers how to set up accessibility testing, and how to apply accessibility principles to new and existing sites using standards-compliant markup and CSS. Exercise files accompany the tutorials.

Topics include:
  • Understanding Flex programming languages
Subjects:
Web User Experience Accessibility
Author:
Zoe Gillenwater

Aligning labels and fields using CSS

>> In the previous movie we began cleaning up the form's appearance in CSS, but there are still some improvements that we can make to the alignment of the labels and their fields. Remember that we floated the items in the mainNAV bar to get them to line up nicely side by side. We'll use a similar technique here. We'll float the label elements so that they'll align better with their matching fields. If you're following along with the exercise files, the page we're working on is named departments.html and can be found in the 08_06 folder of the chapter eight exercise files.

In the CSS styles panel click the new CSS rule button at the bottom, choose tag for the selector type. In the Tag menu, scroll through the lists and select label. Keep define in styles.css selected then click okay. In the CSS rule definition dialogue box click on the block category. Click on the arrow of the Text Align and select right. Next click on the box category.

We want the width of each of the labels to be consistent so that their text fields will cleanly line up on their left side, so click in the width field, type six and in the adjacent menu choose Ms. We can't choose a pixel measurement for the label width because we have no idea how large or small the user's font size is. If we set the width in Ms though, it will adjust based on that font size. Remember that one M is roughly equal to two characters. So a width of six M's would give us about 12 characters before the text would start wrapping.

This is fine for the labels in our particular form. When you're making your own forms, simply adjust this width to fit the length of your longest label. Next, uncheck the same for all box under padding. Click in the right field and enter .5 and then choose Ms from the adjacent menu. This gives us a little bit of space between the right side of the text label and its form field. Finally, click on the float menu and choose left. Now click okay.

Let's preview the page in a browser and see how it's doing. Click on the globe icon in the document tool bar and choose preview in Firefox. A dialogue box will open saying that additional files need to be saved for the preview to work. What this is referring to is the fact that when we made a change to the style sheet, Dreamweaver opened it up but did not yet save it in case we wanted to undo the styles that we added. Before we can preview departments.html Dreamweaver needs to save styles.css, so click yes for it to save that file.

Now our preview opens in Firefox. You'll see that all of the labels are nicely aligned on the right hand side and all of the fields are nicely aligned on the left. There's plenty of space between each field for it to remain readable. Now let's scroll down the page and look at the other field sets. Unfortunately, the labels and radio buttons are very misaligned now in the second field set. The third field set looks okay. But this long label looks a little bit awkward off to the left of its field. What we can do is create special classes for these special cases.

The styles that we just added will work with a majority of the fields in most forms, since most forms are heavily made up of text fields. But for the cases where we want labels to be to the right of its field, or for the cases where the label is long and we want it to be above its field, we'll need to create special classes. Close Firefox. Click on the new CSS rule button at the bottom of the CSS styles panel. We're going to create a special class any time we have a question with multiple options using radio buttons or checkboxes.

We'll name this class options. So delete the default text in the selector field and type .options, but we don't need to style this class itself, instead we need to style the label within this class. That's because what we're trying to do here is override the styles on the label tag that we just set. So now let's specifically target labels that we within items with the class of options. So leave advanced chosen for the selector type. And as a selector, after you've typed .options, type space label.

Leave define in styles.css selected and click okay. We want to remove the floating and the right text alignment, so first click on the block category. Click on the Text Align menu and choose left then click on the box category. Place your cursor inside the width field and type auto. This overrides the width that we previously set on the label element. Auto simply means let the element be as wide as it needs to be.

This will allow the options beside radio buttons and checkboxes to be as long or short as they need to be. Since they're aligned with their radio buttons and checkboxes cleanly on the left side of the text by default, we don't need to worry about setting the width for them to get them to nicely line up like we did with labels that were to the left of text fields. Next, select the float menu and choose none. Again, we're simply overriding the float property that was set on the label element earlier.

Now click okay. We haven't yet applied this class in the page, so there won't be anything to see in Dreamweaver or in a browser. Before we apply the options class, let's create the second class that we'll need for labels that are long and need to be aligned over their fields instead of to the left. Click on the new CSS rule button, leave advanced chosen as the selector type and delete the text in the selector field. These types of long labels are usually rather explanatory in nature so I'm going to call the class explanatory.

Type .explanatory label. Leave define in styles.css selected and click okay. What we want to happen here is again remove the float width and right text alignment. But we also want to tell the label to sit on its own line above its field. We can do that using the display block property. Remember that block elements stack on top of each other. Click on the block category in the CSS rule definition dialogue box then click on the Display menu and choose block from the list of options.

Next click on the Text Align menu above and choose left. Now click on the box category, type auto in the width field, and select none in the Float menu, now click okay. We now have our classes ready to apply. Scroll down the page in design view. Click on the email label of the first radio button, then click on the LI tag shown in the tag selector. Right click or control click on this tag and select quick tag editor, then type space, and a list appears of possible attributes you can add to this tag.

Class is as the top of the list, so double click on class and you'll then be shown a new menu with classes defined in styles.css that we can choose. Choose the options class. Double click on the options class to choose it. You can see that immediately the label jumps back up by the radio button. Repeat this for the phone label of the second radio button. Click inside that label then click on the LI tag in the tag selector. Click inside the phone label then right click or control click on the LI tag in the tag selector.

In the menu that appears choose quick tag editor, type a space and double click on class from the menu that appears. In the second menu then, double click on options. We're done with our radio buttons, so scroll the rest of the way down the page and click inside the last label on the page for the large text area field. Right click or control click on the LI tag in the tag selector and choose quick tag editor. Type space, double click on class from the menu and then this time, double click on explanatory from the second menu that shows.

Again, the label immediately changes its alignment. This time above the form field. Go to file > save to save your page. Then click over to styles.css to save this file as well. Go to file > save. Click back in departments.html. We're now ready to preview in the browser. Click on the globe icon in the document tool bar and select preview in Firefox. Our first field set hasn't changed in appearance.

Our second and third field sets are much improved. Now the radio button items are nicely aligned with their labels. And the long label in the third field set sits above the text area. This is just the beginning of the styles that you can apply to forms using CSS. One thing to note about styling forms, however, is that the operating system has some control over the appearance of form elements, so you can't greatly alter the appearance of the actual form controls themselves. Although this may be a negative for branding purposes, it can be a positive for accessibility because it keeps the form controls from looking radically different than they do on other sites do that users know how to interact with your form correctly.

There are currently no FAQs about Web Accessibility Principles.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Web Accessibility Principles.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.