Read my latest blog entry: Does your web site help, or hurt your business?.
Subscribe to my RSS Feed or by Email.
  • Home
  • About
  • Services
  • Blog
  • Contact
Christopher Ross Building better web sites, one pixel at a time.

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

  • Using CSS to highlight a link
  • Using CSS to disguise a link.
  • Turning your menu list into menu buttons
  • Using CSS to build a horizontal menu
  • How to center content with CSS and HTML
  • How to make a web site look good in multiple browsers.
  • Placing page content in Adobe Dreamweaver
  • Structuring your web site with Adobe Dreamweaver
  • Better HTML Helps Search Engine Results
  • Blog Roundup for the 9th of October 2008
Posted on: Wednesday, October 29th, 2008
Tags: 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

Christopher Ross About the author.
Thanks for taking the time to read my blog. If you don't already know me, my name is Christopher Ross and I'm a web evangelist living in Fredericton Canada. When I'm not writing about the Internet, I'm helping small businesses improve their search engine performance or building better WordPress web sites for clients.

Please feel free to leave a comment below, or contact me if you have any questions.

1 Comment

|
comments rss [?] | trackback uri [?]

One Response to “Adding Rollovers to Your HTML Without JavaScript”

  1. Webkinz Says:
    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

Leave a Reply

iTunes
LEGO - City
HBO
iTunes Jazz
PCSecurityShield
HBO
Total Training DVDs
Peach Pit
iTunes
PCSecurityShield
Tiger Direct
Fujitsu
Recent Comments
  • Electric cars: Very nice post and I gain much more info from this post about, “How to useful my site for my...
  • Internet Marketing Strategies: That is really bad business, with the Internet making the world such a small place,...
  • Adam Love: wtf, that was prety blunt don’t you think?
  • George Matthews: well that’s effective, know of an easy way of title casing static sites, other than...
  • Market Secrets Blogger: At first this one click plugin install worked just fine but now I get the following error:...
  • Rodney@Blogging with WordPress: Nice work Christopher - not too shabby. You must have some pretty good backlinks....
  • david forex trading online: Thank you for letting it slide. I know it is annoying when people use keywords as their...
  • Ikki at SEO Blog: As Mr. forex trading online (I hate it when people don’t put their names on the Name...
  • David: One more strategy of search engine marketing is to create a buzz about your site in the internet. This can be...
  • Internet Marketing Strategies: Nice tutorial! JR Internet Marketing Strategies’s last blog post..Blogging Goodies...
Top Commentators
  • rv for sale (8)
  • Internet Marketing Strate... (7)
  • Electric cars (6)
  • Ikki at SEO Blog (4)
  • forex trading online (4)
  • RNB Love Songs (4)
  • Make Money Online (3)
  • Mike Collins (2)
  • PizzaForADream (2)
  • Webkinz (2)
© Copyright 2009 Christopher Ross. All rights reserved.
  • Follow my posts:
  • RSS
  • Comments
  • Email
  • Other:
  • Privacy