5,661,954 members and growing! (272 online)
Email Password   helpLost your password?
Web Development » HTML / CSS » IE4+     Intermediate

CSS and round corners: Making accessible menu tabs

By Trenton Moss

Using CSS and text instead of relying on graphics
HTMLIE, IE 6.0, Dev

Posted: 24 May 2004
Updated: 24 May 2004
Views: 43,649
Bookmarked: 27 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
10 votes for this Article.
Popularity: 4.00 Rating: 4.00 out of 5
0 votes, 0.0%
1
1 vote, 10.0%
2
0 votes, 0.0%
3
4 votes, 40.0%
4
5 votes, 50.0%
5

Introduction

One of the best websites out there, in terms of functionality, is, and always has been, Amazon. In terms of accessibility though, they're not too good.

The problem

Amazon's menu tabs, for example, look really nice but are totally inaccessible. First of all, they're missing ALT tags. Additionally, the W3Cs accessibility guideline 3.1 (priority 2) clearly states:

When an appropriate markup language exists, use markup rather than images to convey information

This basically means don't use images to display text - site users with poor vision are unable to resize text that's displayed through images. Find out how to resize text in your browser, if you don't already know.

The solution

CSS, as usual, comes to our rescue. Adjust the text size in your browser now. Go on, do it. Did you see how the menu tabs at the top of the screen increased in size with the text and it all fits perfectly. Today, you're going to learn how to do this.

We start with a simple link:

<a href="#">Home</a>

We'll assign it this CSS code:

a { color: #000; background: #fb0; text-decoration: none }

Which gives us:

Sample screenshot

Needs a bit of work, right?

Adding the left corner

We need to make a small image with the same colour: left tab - here's one I made earlier. Let's call this image "left-tab.gif" and place it into the background of this link:

a{
   color: #000;
   background: #fb0 url("left-tab.gif") left top no-repeat;
   text-decoration: none 
}

This new command says that the background image should be "left-tab.gif", the image should be on the left, at the top, and it shouldn't be repeated - kind of obvious really. The result?

Sample screenshot

We're getting there, but we need to move that text over a bit. It's pretty simple to do with a bit of padding:

a { 
   color: #000; 
   background: #fb0 url("left-tab.gif") left top no-repeat; 
   text-decoration: none; 
   padding-left: 10px 
}

Sample screenshot

And the right corner

We can only assign one background image to a tag so we need to make a new tag and assign an image to that. We can use:

<a href="#"><span>Home</span></a>

Now we just assign this background image right tab (another one I made earlier) to the <span> and we're ready to go! We'll call this image "right-tab.gif"

a span {
   background: url("right-tab.gif") right top no-repeat;
}

This code means that every <span> tag within an <a> tag will have this image as its background. And the final result:

Sample screenshot

Perfect! So now you can... wait a minute, can you spot why it's not so perfect? That's right, we forgot to assign some padding to that <span> tag:

a span {
   background: url("right-tab.gif") right top no-repeat;
   padding-right: 10px
}

Giving us:

Sample screenshot

Now that really is perfect! Resize the text again and see how it looks!

Take this further

This article really only touches the basics of what you can accomplish with CSS and navigation. To take it even further, have a look at the article CSS Design: Creating Custom Corners & Borders featured at A List Apart.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Trenton Moss


Trenton Moss is crazy about usability and accessibility - so crazy that he founded Webcredible, an industry leading user experience consultancy, to help make the Internet a better place for everyone. He's very good at information architecture and interaction design.
Occupation: Web Developer
Location: United Kingdom United Kingdom

Other popular HTML / CSS articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
Generalhow to handle gradients ?memberJavaReb9:13 6 Oct '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 24 May 2004
Editor: Chris Maunder
Copyright 2004 by Trenton Moss
Everything else Copyright © CodeProject, 1999-2008
Java | Advertise on the Code Project