views:

28

answers:

2

Had anyone got a problem with a:hover that has position: absolute and is above <img> under IE & Opera

a:hover has background, but <a> hasnt, both has display: block.

Thank you in advance for your help

...

To see the problem please check this webpage: http://bckp.eu/test.html

or

use this code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Test</title>
<style type="text/css">
div {border: 1px solid black; position: relative; height: 200px; width: 500px;}
a.next {right: 0;}
a.prev {left:0;}
.withbackground {background: yellow;}
.nobackground {background: transparent;}
a.link {position: absolute; top: 0; width: 100%; height: 100%; border:0;}
a.link:hover,a.link:focus {background: url(/img/comment.gif) repeat !important;}
</style>
</head>
<body>
<div id="t">
<a class="link nobackground" href="#">&lt;a&gt; without background</a>
<img src="/img/DSC_00641.jpg" height="200" width="500" alt="Dummy img" />
</div>
<p>Doesnt work under IE? <a href="#false" onclick="return a();">Add background</a> | This is not <a href="#" onclick="quirks()">quirks mode</a> <a href="http://www.satzansatz.de/cssd/quirksmode.html"&gt;#&lt;/a&gt;&lt;/p&gt;
<hr />
<div>
<a class="link withbackground" href="#">&lt;a&gt; with background</a>
<img src="/img/DSC_00641.jpg" height="200" width="500" alt="Dummy img" />
</div>
<div>
<a class="link nobackground" href="#">&lt;a&gt; without background, without img</a>
</div>

<script type="text/javascript">
function a() {
document.body.innerHTML+='<style>#t a {background: pink;}</style>';return false;
}
function quirks() {
alert(document.compatMode); return false;
}
</script>
</body>
</html>
+1  A: 

This is one seriously wacky bug. Now, if you really must organize your html the way you have, then IE needs to have the following placed inside the a tag to get it to register with the image.

<div style="position: absolute; filter: alpha(opacity=0); background: red; top: 0px; left: 0px"></div>

But this would be better (have not tested completely across browsers). Organize the html like (no need for a wrapper div):

<a><img /></a>

Make sure the a is not position: absolute (IE7 didn't work with it so), and then set the image to:

img {position: absolute; z-index: -1}

I hope these head you in a direction to solving your problem.

Scott
A: 

Scott, thank you for your answer. This is just example of the problem.

Of course my real code is bigger than that: - 2 tags to navigate prev/next (so I cant put <a><img></a>) - both 's has but with display: none (<a><span>prev</span></a>). display: block doesnt help

z-index doesnt help. position: absolute works, when <a> has background.

I cant have filter: alpha(opacity=0) or opacity=0 because not every browser supports that.

I found odd solution that solves the problem, but dont want to use it: a {background: url(filedoesnotexists);} or i can use for example transparent 1x1 gif file but i would like to find reason of my problem.

Solution with img{position: absolute; z-index: -1;} div{position: relative;} a{position: static;} works exactly the same - no hovering without background above img for ie & opera

I also met another odd thing with that in my main code - will try to reproduce it. (EDIT below)

This is another strange problem - IE works, but only when it has another "layer" and mouse is hovering above this layer. Opera works fine in every case:

http://bckp.eu/test2.html - click Exif info and move mouse over image/new "layer"