CSS Rollovers

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch
CSS Rollovers


Tired of using Javascript for your rollovers? Well, I looked a few tutorials, made some tweaks and now have a very effective way of doing them through CSS. Since IE doesn't support img:hover we'll have to stick with the good ol' a tag.

Before I show the code, I want to explain how it works.

Basically what happens, is you assign a class (must belong to the a tag) to a link. Depending whether you want to use text-links or image-links will determine whether you put text in the link or not. In that class, you set the size of the button, and attach a background that doesn't repeat and is set a position. Now, that background will have all the states (normal, hover, etc) in the one image (acts like a preloader.) On the hover you will just change the position on the image. Works really well.

Now for the code (I'll assume they're using text as their link). Your CSS
Code:
[COLOR=Blue]a.nav {
background-image: url(images/nav_link.jpg);
background-repeat: no-repeat;
background-position: -85px 0px;
display: block;
width: 85px;
height: 21px;
margin: 0; 
padding: 0; 
}
a.nav:hover {
background-position: 0px 0px;
}[/COLOR]

Your link code
Code:
[COLOR=Blue]<a href="home.html" class="nav">Home</a>[/COLOR]

It's that simple. But when you're doing it without text (having the link text in the graphic) you have to make a class for each one. I means a bit more CSS, but can make for some interesting rollovers. You can also add more states by doing something similar to the "a.nav:hover."
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I think you need to provide an example of what the image would look like, for those who don't know.
 
0
Close
Not bad, i would of gone in to more detail thought about what else you can and an example would be nice..
 
0
Close
Absolutely, an example would be nice.
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back