CSS animated hovers by eckert
CSS hovers, animated, no client side applications required. Too good to be true?
I was looking for a way to do animated hovers, without having to use flash or javascript. Not that there is anything wrong with these, but anytime I can avoid hoping that someone will have the proper apps installed within their browser, I prefer to take that route.
So how do I do it?
Simple CSS and animated gifs.
First, make an animated gif the size of you nav button:
Next, a little CSS:
#nav {
height: 35px;
width: 500px;
}
div.button {
float: left;
width: 100px;
height: 35px;
margin: 0 3px 0 0;
background: #fff;
border: 1px solid #000;
}
div.button a {
display: block;
margin: 0;
padding:0;
width:100%;
height:100%;
overflow:hidden;
font: bold 13px Georgia, serif;
color:#039;
text-decoration: none;
background: #fff;
}
div.button span {
display: block;
margin:0;
padding: 9px 0 0 0;
text-align: center;
}
div.button a:hover {
background: url( 'http://itscalledwebdesign.com/files/gif_hover/bg03.gif' ) top center no-repeat;
color: yellow;
}
Next, the following div is placed:
<div id="nav"> <div class="button"><a href="#"><span>Nav 1</span></a></div> <div class="button"><a href="#"><span>Nav 2</span></a></div> <div class="button"><a href="#"><span>Nav 3</span></a></div> </div>
You are pretty much just making a div and placing the animated gif as the image for the hover. In this example, the “a” simply has a white background.
CLICK HERE to see how it looks, it’s the “Fast” example.
View the CSS and source of that example page to see that the other examples are set up using the same code. You just need to use different animated GIFs as the hover image.
One thing you need to think about is the possibility that animations are turned off on the users computer. The only problem this might cause will be if you have your hovered text turn into the same color as the original background. That would then cause the text to disappear.
I would suggest trying it with the animation turned on and off just to see what it would look like.
So there you have it. Simple, quick CSS animated hovers.
Tags: CSS, Flash, hovers, java, javascript
December 21st, 2008 at 3:58 am
Wow, nice piece of code! I’ve been looking for something like this for a while now. I wanted to use the code on my member page. A list of member avatars appears and I wanted the .gif animantion to play only when hovered over. This code above did the trick!
cheers and happy Christmas, awM,
May 3rd, 2010 at 11:24 am
thank!
January 10th, 2011 at 12:27 pm
you NAILED it. i’ve been trying to figure this out for a while, and your code is so simple and works perfectly! thanks so much!
April 8th, 2011 at 9:59 am
This looks really great! Been wanting to have some animated gif control on my site. Just one problem: sometimes it animates on hover, but other times it just goes to the last frame and stays static on hover. Do you think there’s a way to have the gif play from the beginning every time on a hover?
April 16th, 2011 at 8:05 pm
The first time I looked at your examples it work but only that once.
Thanks for the code anyway!
November 26th, 2011 at 12:15 am
Fenix Lights Luminance…
[...]It’s Called Web Design » CSS animated hovers[...]…