views:

1396

answers:

6

I haven't got a unique problem, but for the life of me I can't figure out what I'm doing wrong.

I have a page that has a series of sections. Part of the section is a little image. When the image is clicked, I want to show a custom control. Showing the control is trivial, set the z-index a bit higher to ensure the control is on top of everything.

But the user can still interact with the sections behind the control.

To stop that, I added a "blanket". Basically a div that is the size of the document with the following CSS (in jQuery syntax) -

{
  position: 'absolute',
  top: 0,
  left: 0,
  width: '100%',
  height: $(document).height(),
  display: 'none',
  zIndex: 1,
  backgroundColor: '#FF0000'
};

Yeah...the background is red so I can see it for testing. I set opacity to 0.1 (light blur). I then set the z-index of my custom control to 2 so that it is on top of the blanket.

This works perfectly in FireFox, Chrome, and Safari, but not in IE.

The custom control is not a child of the blanket.

The goal is to have the following document covered by blanket with control on top of blanket to interact with it. This is what I get on all browsers except IE. On ie...it goes document with control and both are covered by the blanket.

Answer

scunliffe was the closest (answered in a comment I can't link to). The custom control is inside of a relatively positioned div (several down actually). the blanket was simply appended onto the end of the body. Therefore it was outside the relatively positioned div and started it's own z-index stack (as documented here). Since IE 6/7 are broken in this regard, no matter what I set the z-index to, it would always be below the blanket.

So I moved the blanket to be the first child inside the relatively positioned div. This isn't 100% complete yet because if you scroll (which I can't stop with this solution), the blanket div is only the height of the visible content. I now have to figure out how to get the complete height of the content (visible and non-visible).

A: 

Here is how we do oppacity on our project:

.SomeStyle
{
filter:alpha(opacity=10);
-moz-opacity:.10;
opacity:.10;
}

That tests fine on IE 6 & 7 and FF 2 & 3. I believe it works in Safari as well.

Jason Jackson
It's not the opacity I'm having a problem with. It's the z-index of the custom control. The blanket shows up fine. But the custom control is underneath the blanket even though it has a z-index higher than that of the blanket. That's what I'm trying to figure out.
Justin Rudd
where did you add the "blanket" IE creates new stacking indexes that you can not go higher than in certain cases. I would ensure that your control is lower in the DOM than the blanket.
scunliffe
You might make that a little more obvious in your question. I just re-read you question and it isn't obvious you are asking that.
Jason Jackson
Hey scunliffe, I think you've hit the problem. I found this (http://aplus.rs/lab/z-pos/) that shows the problem on IE. Since the blanket is in the DOM after my control, it screws up the z-index stacking.
Justin Rudd
@scunliffe : You should put that comment in an answer so Justin can mark this answered.
sep332
+1  A: 

Make it a habit to include a much higher z-index. Use the following:

z-index:20000;

And of course, up the z-index on your custom control. The high z-index fixed my similar problem.

Mike
yeah...I added z-index 10000 to blanket and z-index 20000 to the custom control. The control still shows up under the blanket.
Justin Rudd
A: 

You dont mention what the custom control consists of however if you have a select element in your custom control then this causes modal issues in ie (cant remember if they fixed the issue in ie7). Anyway this info may help you resolve your problem. Youll need an iframe shim to prevent it showing through the overlay. Lots of scripts about to do this for you.

more info

and here

redsquare
No select tag. Just a text box a few checkboxes.
Justin Rudd
+1  A: 

I had trouble with this too. The only way I found create a non-penetrable shield was to put a picture in the background of the DIV (a transparent GIF worked for me). And then you still have to intercept keyboard events to prevent navigating to the control.

Vilx-
an image is not required, but the keyboard events is so important to note
annakata
I think IE6 had the problems that had the need for an image.
Vilx-
A: 

Just to toss my hat in...

I just implemented this a short while ago and I used:

div#shade-box {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background: #000;
    opacity: 0.7;
    filter: Alpha(opacity=70);
}

Obviously you could change or remove the background color. I was adding this div to the DOM through Javascript so I didn't need to worry about the z-index.

Known to work in FF and IE7.

beardog
+1  A: 

scunliffe was the closest (answered in a comment I can't link to). The custom control is inside of a relatively positioned div (several down actually). the blanket was simply appended onto the end of the body. Therefore it was outside the relatively positioned div and started it's own z-index stack (as documented here). Since IE 6/7 are broken in this regard, no matter what I set the z-index to, it would always be below the blanket.

So I moved the blanket to be the first child inside the relatively positioned div. This isn't 100% complete yet because if you scroll (which I can't stop with this solution), the blanket div is only the height of the visible content. I now have to figure out how to get the complete height of the content (visible and non-visible).

Justin Rudd