Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

absolute positioned anchor tag (with no text) not clickable in IE

I have two anchors positioned absolute on top of an image, the links are clickable in other browsers (Chrome, FF, Safari) but not in IE (tested in 8 & 9 so far)

The strange thing is if I give the links a background-color they are clickable, however if the background-color is set to transparent (which is what I want) they are no longer clickable, I've also tried setting zoom:1 but no luck. I guess the hasLayout bit in IE went away with IE 8/9 so guessing zoom doesn't matter now for this kind of issue.

Any ideas to make these links show up in IE 8/9 with a transparent bg?

Here's the fiddle I've been working with: jsFiddle example

I have the following HTML layout:

<div id="content">     <img src="http://placehold.it/724x300" width="724" height="300" alt="woot" />      <div id="countdown"></div>      <a id="link1" href="http://www.stackoverflow.com" title="link1"></a>     <a id="link2" href="http://www.stackoverflow.com" title="link2"></a> </div> 

and CSS:

body {text-align:center;} #content {position:relative; width:724px; height:300px; margin:0 auto;}  #countdown {position:absolute; width:650px; height:110px; top:100px; left:30px; background-color:blue;}  #link1 {position:absolute; width:520px; height:35px; bottom:20px; left:0;} #link2 {position:absolute; width:200px; height:35px; bottom:20px; right:0;} 
like image 843
MikeM Avatar asked Aug 02 '11 15:08

MikeM


2 Answers

I have had this exact problem before and it has always annoyed the hell out of me. I'm never sure why it happens, but I always create a 1px by 1px transparent PNG (or GIF) and use that in your background declaration like so:

a { background: url("/path/to/image.png") 0 0 repeat; } 

Hope this helps.

PS - Don't specify any actual background colour with this. Just use the example above and it should work.

In addition to this, try and set your anchor tags to display as block and perhaps also insert a non-breaking space in them (since they are empty at the moment and that might be tripping IE up):

a { display: block; background: url("/path/to/image.png") 0 0 repeat; }  <a href="#">&nbsp;</a> 
like image 200
Michael Giovanni Pumo Avatar answered Sep 20 '22 21:09

Michael Giovanni Pumo


You can do it using the mentioned background-image trick. When you do not want to use a transparent image for this, just use an unknown scheme or about:blank in the image URL.

a { background-image: url("iehack:///"); } 

or

a { background-image: url("about:blank"); } 

This works at least in IE 8 + 9 (the only IEs I tested) and in current versions of Firefox and Chrome. It is still valid CSS and causes no additional traffic. The first "hack" may give a JS error in Chrome (and maybe others) when using jquery. The latter only (but surely) gives a MIME-Type warning in Chrome due to the wrong MIME-Type of the about:blank document.

like image 35
Dio F Avatar answered Sep 19 '22 21:09

Dio F