Adding Rollovers to Your HTML Without JavaScript
Welcome to my blog, please feel free to subscribe to my RSS feed or leave a comment.
In my last tutorial I showed you how to build a simple horizontal menu in HTML with only a few lines of CSS. Let’s take that same HTML code and use it to increase usability and improve the overall look of your site.
The HTML
This is the same HTML used in our last article:
<div class=’menu’>
<ul>
<li><a href=’index.php’ title=’Home’>Home</a></li>
<li><a href=’about.php’ title=’About Me’>About Me</a></li>
<li><a href=’contact.php’ title=’Contact Me’>Contact Me</a></li>
</ul>
</div>
The CSS
In CSS there are a few different states an anchor tag (<a>) can be. You can be:
- a:link - the default state
- a:visited - after you’ve been to the page
- a:active - after you’ve clicked it but before you’ve left the page
- a:hover - when your mouse is over the link
To make a page truly optimized for usability we can change the state these menu items appear in.
.menu a:link {
text-decoration: none;
color: #FF0000;
border-bottom: dotted 1px #FF0000;
}
This CSS changes the color of the links to Red (#FF0000) and removes the underline from the links. Personally, I don’t like the default underlines so I like to replace them with a dotted line instead.
Next we want to assign a special event when the user has placed their mouse over one of your text items. To do this, we affect the a:hover CSS. Also, while I’m in there I am going to add a special event to the a:active CSS which will change the color when the user clicks the link but before they leave the page. This ensures they know they’ve clicked the link.
.menu a:hover {
color: #0000FF;
border-bottom: dotted 1px #0000FF;
}.menu a:active {
color: #00FF00;
border-bottom: dotted 1px #00FF00;
}
Using the two states above, the user is now aware that they’ve entered a clickable zone because the link changes color and when they click the option, it changes color again to let them know they’ve clicked. There you go, three simple CSS commands to make your page more usable.
Other Posts of Interest
Posted on: Wednesday, October 29th, 2008Tags: css, html, usability
Posted in Learning | | Read more
Did you find this article useful? You're welcome to post a link to this website along with the title but please don't copy the whole article. You can also link back using the following code:
<a http://www.thisismyurl.com/tutorials/adding-rollovers-to-your-html-without-javascript/" rel="bookmark" title="Adding Rollovers to Your HTML Without JavaScript">Adding Rollovers to Your HTML Without JavaScript</a>
About the author.










November 1st, 2008 at 6:14 pm
It’s also OK to use links to wrap other elements if you want to do more complicated rollovers