1.866.PIXELMILL (1.866.749.3564 US/Canada)

Search Support

Search our knowledgebase? Enter keywords or article id:

> go to search support


Support Index


Help and Support


Search

Go back to search results

Enter keyword or id#:




Promotions


Quick Links

Printable Article

Make Rollover buttons using CSS

Article ID: KB101543

See Printable PDF version of this tutorial...

Imagine being able to upgrade your navigation by simply adding a new HTML link to a table cell or layer without creating new images and modifying JavaScript code! With this technique, you can use rollover images as buttons and update them by adding simple hyperlink code... all done with Cascading Style Sheets.

Here's how:

  1. Go to your documents folder and make a new web folder called "css_navigation."
     
  2. Open up your text editor (such as Windows NotePad).
     
  3. You may be already acquainted with the a:link a:hover style rules. They allow your hyperlinks to have a different color when the mouse pointer is floating over them. We are going to use CSS to expand on this a little.
     
  4. In your text editor type this code exactly as it appears here:

    p.navbuttons a {
    color: #000000;
    text-decoration: none;
    background-color: #A2AAB5;
    display: block;
    padding: 3px 0px 3px 12px;
    width: 150px;
    border-top: 1px solid #EEEEEE;
    border-right: 1px solid #666666;
    border-bottom: 1px solid #666666;
    border-left: 1px solid #EEEEEE;
    background-repeat: no-repeat;
    }


    This class defines the way that your link will appear in its "upstate" (untouched by the mouse pointer).

    You will see what each of the things in this class does later when you preview your page in the browser.
     
  5. Carriage-return and type this next:

    p.navbuttons a:hover, p.navbuttons a:active {
    background-color: #333333;
    color: #FFFFFF;
    background-repeat: no-repeat;
    }


    This Class sets the rules for the way the browser will show the buttons in their "hover" or mouseover state as well as their "active" state (the "active" state is when the user clicks on the button).
     
  6. Now go to File > Save as and save this file in your web folder as "stylesheet.css."
     
  7. Now make a new HTML document. If you are using NotePad or a different text editor, type this:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    < html>
    < head>
    < title>My CSS Navigation</title>
    < meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    < /head>
    < body>

    </body>
    < /html>

     
  8. Go to File > Save As.. and save this document as "index.htm" in the same folder as the CSS document you made.
     
  9. What we are going to do now is link your external style sheet (stylesheet.css) to your newly created HTML page in order to make the rules you just created apply.

    You are going to use this code to link it:

    <link href="stylesheet.css" rel="stylesheet" type="text/css">


    Here is where it will go:

    < html>
    < head>
    < title>My CSS Navigation</title>
    < meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="stylesheet.css" rel="stylesheet" type="text/css">

    < /head>

     
  10. Now we are going to add a hyperlink to that same page, just to see how things are going. Add this somewhere between <body> and </body>:

    <p><a href="anypage.htm">your link text</a></p>

     
  11. Preview it in your browser... NO CHANGE!!
     
  12. The reason for this is that you have not told the browser to apply your style sheet rules to this link.
     
  13. It's easy to fix this - change the link code so that it is commanding your browser to display your link as you have decided it should be:

    <p class="navbuttons"><a href="anypage.htm">your link text</a></p>

     
  14. NOW LOOK! You should have a page with what looks slightly like a navigation button that changes when you put your mouse over it? Yes? Hope so!

Taking it a step further... Add Images!

Instead of only having plain old solid colors, why not use a graphic? It's easy:

  1. In the p.navbuttons a class add a line like this that links to your upstate image:

    background-image: url(yourupstateimage.gif);


    Your p.navbuttons a class will look like this:

    p.navbuttons a {
    color: #000000;
    text-decoration: none;
    background-color: #A2AAB5;
    display: block;
    padding: 3px 0px 3px 12px;
    width: 150px;
    border-top: 1px solid #EEEEEE;
    border-right: 1px solid #666666;
    border-bottom: 1px solid #666666;
    border-left: 1px solid #EEEEEE;
    background-image: url(yourupstateimage.gif);
    background-repeat: no-repeat;
    }

     
  2. Then for your mouseover state, add a slightly contrasting image to the p.navbuttons a:hover, p.navbuttons a:active class, like this:

    p.navbuttons a:hover, p.navbuttons a:active {
    background-color: #333333;
    color: #FFFFFF;
    background-image: url(yourmouseverimage.gif);
    background-repeat: no-repeat;
    }

This technique should work in all but the older browsers like Netscape 4 and the MS explorer versions of the same era. In older browsers, even though the button will not render with the rollover effect, the links remain active and legible.

This tutorial was provided by Gordon Mac from gmaq.


Was this helpful?

Please rate this article:

Not helpful Very helpful
1 2 3 4 5 6 7

Email address: (not required)

(Please provide your email address if you would like PixelMill support to follow-up with you about your comment. You're email address is NOT REQUIRED to submit a comment.)

Comments: (How can we improve this article?)


Clicking "Submit" will not clear this page.


link to this page: http://www.pixelmill.com/support/al0/kb101543.htm
permalink to this article: http://www.pixelmill.com/support/kb101543.htm

Back to top

Items you recently viewed:


pm46519htdl1
$98.00

pm45887dwdl1
$94.00

pm45779fpdwtdl1
$87.00

pm46207fpdwtdl1
$98.00


PixelMill EDU

Introducing...

PixelMill EDUâ„¢ is an innovative and proprietary online training series designed to aid the do-it-yourself Web builder in transitioning to new Web editors, coding standards, and Web technologies.

Webinars and Seminars:

FrontPage to SharePoint Designer Series
This is a 6-Week series designed to give you strong exposure to the new SharePoint Designer web editor and interface, along with examples of working with Windows SharePoint Services and tips for transitioning from FrontPage.
Register Now!

Tables to Tableless CSS Series
This is a 6-Week series designed to help you transition from building Tables-based Web site layouts to working with CSS to edit and build Tableless Web site layouts. For all Web builders using Dreamweaver, Expression Web, or any other web editor.
Register Now!

FrontPage to Expression Web Series
This is a 6-Week series designed to give you strong exposure to the new Expression Web software and interface, along with tips for transitioning from FrontPage.
Register Now!

Learn more and register!

ADVERTISEMENT
adventisement