views:

66

answers:

3

Hi all!

I have a small thumbnail image that I wish to change when the mouse rolls over it. I was wondering if there was a way to do this without swapping images on the rollover. For example, through CSS could I have the opacity change on rollover? If you have any other ideas about how to manipulate the image with CSS on rollover for making a change I am open.

Thanx!

+2  A: 

Try using the :hover style on a tag. It may not be supported very well in early IE editions. But you can do something like:

img {
    border: 1px solid black;
}
img:hover {
    border: 1px solid white;
}
Dan Breen
Specifically, IE<=6 doesn't allow dynamic pseudo-classes to select any elements other than hyperlinks.
melhosseiny
+2  A: 

With CSS3, there is an opacity option. This way you wouldn't be forced to reload an image when they hover above something.

#div {
  background-image: url('blah.png'); 
}

#div:hover {
  opacity: 0.5;
}

I'm not exactly sure if that's the right way to use it so you should use google for more examples. However, you should be careful because not all browsers might be supporting CSS3 yet.

Marcin
This is good information. Thank you!
computersaurus
Add -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=x)" for IE8, filter:alpha(opacity=x) for IE5-7, -moz-opacity for older versions of FF and -khtml-opacity for older version of Safari and Konqueror.
melhosseiny
+4  A: 

You could put both images in one bigger image, use it as a background image and change only the position on roll-over.

jeroen
Those are called CSS Sprites, I think it's what you are searching for, view this link for more informations : http://css-tricks.com/css-sprites/
Dominique
I am familiar with CSS Sprites. If changing the opacity with CSS is too troublesome this is the way I will go. Thanx for the link!
computersaurus
@Dominique, that's the word I was looking for :-)
jeroen