Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invisible div over div does not work in IE8

I'm trying to create an invisible div, over the facebook comments plugin in order to disable the plugin's functionality in an Editor View. This invisible div works in all browsers except IE8. How can I fix this?

HTML:

<div id="container">
   <div id="coveriframe"></div>   
    <div data-bind-component="fbml: fbml">(RENDER JS COMMENTS VIA KO)</div>
</div>

Try in IE8:

http://jsfiddle.net/pkbz4/19/

  • The above code works in ALL other Major browsers. WTF Microsoft?

Stylesheet:

    #container {
        width: 100%;
        height: 100%;
        position: relative;
    }

    #navi, 
    #coveriframe {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
    }

    #coveriframe {
        z-index: 10;
   }
like image 584
JZ. Avatar asked Jul 16 '12 21:07

JZ.


People also ask

How to create an overlay effect for two <div> elements?

Creating an overlay effect for two <div> elements can be easily done with CSS. This can be done with the combination of the CSS position and z-index properties. The z-index of an element defines its order inside a stacking context.

How to add a margin to a Div using CSS?

Use a <div> element with the class named “container”. Add two other <div> elements within the first one. Add classes to them as well. Specify the width and height of the "container" class. Set the position to "relative" and add the margin property.

How to center a Div vertically and horizontally without fixed size?

How to center a div vertically and horizontally (modern methods, without fixed size!) Method 1: Center a div in the middle of the viewport Method 2: Center div vertically and horizontally inside an other div


2 Answers

I've done this several times in IE8. The solution that works for me is to assign a background color to the div and then set opacity to 0. IE8 then recognizes the div as "existing" above the rest of the content. I also find setting position: absolute and all four directions to 0 is more reliable than 100% width and height. Like this:

#coveriframe {
  position: absolute;
  top: 0; 
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3007;
  background: #fff;
  filter: alpha(opacity=0);
  opacity: 0;
}

Here's my update to your jsfiddle: http://jsfiddle.net/pkbz4/21/

like image 136
Zach Shipley Avatar answered Sep 23 '22 23:09

Zach Shipley


CSS Specification says:

The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to 'auto'.

Basically, In older versions of IE (including IE8) percentage heights are based on the height of the parent element. If the parent element doesn't have an explicit height, the percentage is ignored and set to Auto (in this case, 0px).

So, to fix this, you'll either want to explicitly set the height/width of #coveriframe or its parent. One thing you could try is setting the height of html and body to 100% (I'm assuming those are the parent elements).

html, body { height:100%; }

#container {
    width: 100%;
    height: 100%;
    position: relative;
}

#navi,
#coveriframe {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

#coveriframe {
    z-index: 10;
}
like image 33
Cody Bonney Avatar answered Sep 22 '22 23:09

Cody Bonney