Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

z-index problem in IE with transparent div

Tags:

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?

like image 587
Preli Avatar asked Jun 25 '11 21:06

Preli


People also ask

Why Z index is not working with div?

z-index only works on positioned elements (relative, absolute, fixed, sticky) so if you set a z-index on an element with a static position, it won't work.

How do you fix Z index issues?

To sum up, most issues with z-index can be solved by following these two guidelines: Check that the elements have their position set and z-index numbers in the correct order. Make sure that you don't have parent elements limiting the z-index level of their children.

How do I make a DIV container transparent?

First, we create a <div> element (class="background") with a background image, and a border. Then we create another <div> (class="transbox") inside the first <div>. The <div class="transbox"> have a background color, and a border - the div is transparent.


2 Answers

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); 
like image 103
Mo Valipour Avatar answered Oct 02 '22 15:10

Mo Valipour


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

like image 30
Ryan Avatar answered Oct 02 '22 14:10

Ryan