Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change an image <img> on mouse rollover (hover)

Tags:

html

css

image

How can I change an image (set using <img> tag, which is not a <div> or <some_selector> background, that can be easily solved by changing background or background-image attribute on :hover in CSS) on mouse rollover (hover) like the favorite tag remove button in stackoverflow homepage, in which the (X) image becomes red on hover ?

like image 201
Alfred Avatar asked Mar 07 '11 12:03

Alfred


1 Answers

HTML

<div id="css-image-swap-1">
<img id="swap-1" src="default-image-url" alt="CSS image swap" />
</div>

CSS

#css-image-swap-1{
    width:300px; height:150px; background:url(swap-image-url);
}
#css-image-swap-1 img:hover{
    opacity:0;
}
like image 166
Myles Gray Avatar answered Sep 22 '22 06:09

Myles Gray