views:

519

answers:

1

I need a div with picture bg to overlay an image (with some amount transparency) when hovered on. I need to be able to have one transparent overlay that can be used and reused throughout the site on any image. My first attempt was round-about to say the least. Because I found out you cannot roll-over an invisible div I devised a sandwhich system in which the original image is the first layer, the overlay is the second layer, and the original image is third layer again. This way, when you roll-over, the original image disappears revealing the overlay image over the original image:

http://www.nightlylabs.com/uploads/test.html

So it works. Kinda. Because of you cannot interact with an visibility:invisible element (why?!) the roll-over flickers unless you rest the cursor on it.

Any help? This method is bad so if anyone has a better one please comment.

+2  A: 

I used the following css and its fine.

#container { position:relative; width:184px; height:219px;}
    .image { background-image:url(alig.jpg); position:absolute; top:0; left:0; width:184px; height:219px; z-index:2;}
    .overlay { background-image:url(aligo.png); position:absolute; top:0; left:0; width:184px; height:219px; z-index:3;}
    .top-image { background-image:url(alig.jpg); position:absolute; top:0; left:0; width:184px; height:219px; z-index:4;}
    .top-image:hover { background-image:none;}
XGreen
nicely done. thanks.
Juventus
quick question, though: ie7 isn't liking it. any ideas?
Juventus
Please explain what you are experiencing in ie7 a bit further as I have it displayed nicely in ie7
XGreen
Slightly modified but same principle:http://www.nightlylabs.com/uploads/test.htmlDoesn't work on Ie7. Had to change it because the previous method was too complex and I need the image to appear in the markup because it's dynamically generated.
Juventus