Jump to content

[SOLVED] CSS Rollover working but ACTIVE link isnt!


spikypunker

Recommended Posts

Hey guys, i've got this rollover working but the client wants it to stay "down" when on the page they are currently on, this should work????

 

a.rollover {
display: block;
width: 98px;
height: 20px;
text-decoration: none;
background: url("images/button.gif");
padding-top:5px;

}

a.rollover:hover {
background-position: -98px 0;
}

a.rollover:active {
background-position: -98px 0;
}

:active has no relation to the current page. It only refers to the state where the button has been clicked, before the page has reloaded to the target of the link.

 

If you want it to be active on the page you are viewing, you can do it like this. First, give an ID to the body on each page. For example, if you have these pages:

 

* index

* about us

* contact

 

Then you would give the three body tags on those pages the following IDs:

 

<body id="index">
<body id="about_us">
<body id="contact">

 

So if you have your navigation like this:

<ul id="navigation">
  <li><a class="index" href="index.html">Index</a></li>
  <li><a class="about_us" href="about_us.html">About Us</a></li>
  <li><a class="contact" href="contact.html">Contact</a></li>
</ul>

 

Then you can set up your CSS like this:

 

#navigation a
{
  color:blue;
}
#navigation a:hover
{
  color:red;
}

#index .index, #about_us .about_us, #contact .contact
{
  color:green;
}

#index .index:hover, #about_us .about_us:hover, #contact .contact:hover
{
  color:white;
}

 

This will give the links a blue color with a red rollover, and on the active pages the link will be green with a white rollover.

Ok i think i was over complicating a simple problem, all i've done to fix it is duplicate the link rule and then add an ON to the name, then changed this on each page, i only have 5 pages so it wasnt needed to overthink it :) Thanks for your help!

 

a.rollover {
   display: block;
   width: 98px;
   height: 20px;
   text-decoration: none;
   background: url("images/button.gif");
   padding-top:5px;

   }

a.rolloverON {
   display: block;
   width: 98px;
   height: 20px;
   text-decoration: none;
   background: url("images/button.gif");
   padding-top:5px;
   background-position: -98px 0;
   }

a.rollover:hover {
   background-position: -98px 0;
   }
   
a.rollover:active {
   background-position: -98px 0;
   }

 

Simple as that, then obviously on each page i changed which button used the new rolloverON class, simples

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.