z-index problem in IE with transparent div

2019-01-24 00:29发布

I have a transparent div-element with a higher z-index than an img-element on the same page. But Internet Explorer is acting as if the img-element would have a higher z-value when it comes to click events.

<!DOCTYPE html>
<html>
<head>
    <title>Demo</title>
</head>
<body style="margin:0;padding:0;">
    <img src="7player.png" alt="7player" width="60" height="60" style="position:absolute; left: 100px; top: 100px; z-index:10" />
    <div style="width:100%;height:100%;position:absolute;z-index:900;" onclick="alert('hello');"></div>
</body>
</html>

When clicking on the image nothing happens altough the click event of the div-element should be fired (works in Chrome for example).

Is there any workaround or fix for my problem?

5条回答
神经病院院长
2楼-- · 2019-01-24 00:57

This is still a bug in IE11, but not Edge. The following solved my problem by creating a background that "looks" transparent but has a color.

background: rgba(255,255,255,0.0);

Slightly better that the filter solution above, if you want only the background to be transparent, but not the contents of the object.

查看更多
太酷不给撩
3楼-- · 2019-01-24 00:58

I have tested the Suggestion given by Preli background:white;filter:alpha(opacity=1), and it is working fine. See the Demo in IE:

http://jsfiddle.net/VMrNF/11/

查看更多
我命由我不由天
4楼-- · 2019-01-24 01:00

Using a transparent image seems like a reasonable work-around for IE. This was answered already here:

IE z-index trouble on element with transparent background

查看更多
ら.Afraid
5楼-- · 2019-01-24 01:05

add left:0 to div, click event available

tested in ie9

查看更多
老娘就宠你
6楼-- · 2019-01-24 01:09

In fact, your div "Doesn't have any background",

You need to give it a color background (e.g. white) with opacity=0.01.

For example:

 background:white; filter:alpha(opacity=1);
查看更多
登录 后发表回答