4

I have a parent div which has its position as fixed. What i'm trying to do is to get the child div1 to stand out when I blur the page but the entire parent div stands out. After having read a lot of posts which said that the parent div overrides the z-index and the child's z-index has no meaning, I'm stuck here not knowing how to make this work.

If not getting this to work, can anyone help me with a solution for this?

enter image description here

Rohit
  • 207
  • 1
  • 5
  • 14

2 Answers2

3

This is easily achievable when you don't actually contain the intended children in the parent element, but instead fake hierarchy visually while keeping the DOM layout flat. A sample is built below:

http://jsfiddle.net/4KLRU/1/

HTML:

<div id="container">
    <div class="child">Something</div>
    <div class="child behind_parent">Something else</div>
    <div class="child">Something else entirely</div>
    <div id="parent"></div>
</div>

Notice that the parent element isn't actually around the so-called children elements.

CSS:

#container {
    position: fixed;
    padding: 10px;
}

#parent {
    background: orange;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
}

.child {
    position: relative;
    background: red;
    margin: 5px;
    z-index: 2;
}

.behind_parent {
    z-index: 0;   
}
Etheryte
  • 24,589
  • 11
  • 71
  • 116
0

Without knowing exactly what your markup looks like, you could try the following approach:

#parent {
  position: fixed;
  ...
}

#child {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  ...
}
WynandB
  • 1,377
  • 15
  • 16