...">

Why does my overlay cover some elements but not all?

I am trying to create my own, modal dialog using divs:

html:
<div id="overlay"> </div>    
<div id="popup">  

    <input type="submit"/>
    <p>Some text</p>

</div>

css:
#overlay{
    width: 100%;
    height: 100%;
    position: fixed;
    left: 0px;
    top: 0px;
    background-color:#000;
    opacity: .75;
    z-index: -1;
}

#popup {
    position: absolute;
    text-align:center;
    z-index: 1000;
}

      

http://jsfiddle.net/wfsaxton/fq7mhefa/

I'm not sure why, but my overlay not only closes the page, but also closes part of the popup (background and text). I only want it to close the page in the background ... the popup should be completely above the overlay.

Any ideas what might be going on?

+3


source to share


4 answers


#overlay{
    width: 100%;
    height: 100%;
    position: fixed;
    left: 0px;
    top: 0px;
    background-color:#000;
    opacity: .75;
    z-index: 5;
}

.popup {
    display: none;
    position: absolute;
    text-align:center;
    z-index: ;
}
      

<div>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</div>

    <div id="underlay">  
        <input type="submit"/>
        <p>Some text</p>
    </div>

<div id="overlay">  
    <div id="popup">  
        <input type="submit"/>
        <p>Some text</p>
    </div>
</div>
      

Run codeHide result




You set your overlay to -1, which means it is below the default z-index: 0 for almost every html element.

+3


source


to overlay everything, the z-index

value must be greater than everything else. yours -1

.



+2


source


You need to change the z-index of the overlay and popup.

You can specify #overlay z-index from 5 and .popup z-index -1 (or whatever numbers you want to use). Then you should be good to go.

0


source


Uh, it was that simple. My #popup didn't have a highlighted background, so it was transparent by default in my opinion.

Just added:

#popup {
    ....
    background-color: white;
}

      

And now it works: http://jsfiddle.net/wfsaxton/fq7mhefa/12/

0


source







All Articles