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

前端 未结 6 896
青春惊慌失措
青春惊慌失措 2020-12-07 15:18

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)

相关标签:
6条回答
  • 2020-12-07 15:58

    @tw16's comment mentioning invisible got me thinking about opacity.

    Combining IE's filter:alpha(opacity=0) with background-color:#fff (or any color) appears to be a good solution for this. Tested and works in IE 7-9 (6 isn't applying the opacity filter for some reason but I'm not required to support 6 so this will work)

    The 1x1 image solution is globally effect so I'm going to give the check to him.

    Thanks for the answers.

    0 讨论(0)
  • 2020-12-07 15:59

    IE has a nasty habit of not making links work as expected when they don't have any content. To fix this, give each link a   for content.

    Another thing to try is to set display: block; on the links to make IE flow them as block-level elements rather than as in-line elements. This can also help is you need the links to be empty.

    0 讨论(0)
  • 2020-12-07 16:00

    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.

    0 讨论(0)
  • 2020-12-07 16:07

    I had the same problem. My working solution was to add a border to the appropriate anchor. Like the following example. One advantage is, you need no extra image.

    a { border-right: 1px solid transparent }
    
    0 讨论(0)
  • 2020-12-07 16:09

    Transplanted from a comment I posted some time ago.

    Little longer, but still no traffic, base 64 encoded transparent gif:

    background-image: url('data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICR‌​AEAOw==')
    

    This has its own pros/cons, but can be useful. Also:

    background-color: rgba(0,0,0,0)
    

    I've used this one more recently

    0 讨论(0)
  • 2020-12-07 16:13

    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>
    
    0 讨论(0)
提交回复
热议问题