2015-04-30 56 views
3

我试图创建自己的,莫代尔,对话框使用的div:为什么我的覆盖层覆盖了一些元素,但不是全部?

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/

我不知道为什么,但我的叠加不仅覆盖了网页,而且还覆盖弹出部分(背景和文本)。我只希望它能够在背景中隐藏页面......弹出窗口应该完全位于叠加层之上。

任何想法可能会发生什么?

+0

因为它具有较高的z-index? - http://jsfiddle.net/fq7mhefa/3/ –

+1

尝试z-index:999覆盖。 –

+0

popup具有比叠加更高的z-index。因此,我会假设弹出窗口会出现在叠加层上方。只有某些标签(如输入)位于叠加层上方。其余部分(如文本和背景)位于叠加层下方。 – wsaxton

回答

2

覆盖所有东西,z-index值必须大于其他所有东西。你的-1

+0

对不起,我不清楚。我希望弹出窗口位于叠加层之上,叠加层位于页面的其余部分之上。此时,即使弹出窗口的Z索引大于叠加层的Z索引,弹出窗口的部分仍会出现在叠加层下面。 – wsaxton

3

#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>

您设定叠加为-1,这意味着它是默认的z-index如下:0几乎每一个HTML元素。

+0

对不起,我不清楚。我希望弹出窗口位于叠加层之上,叠加层位于页面的其余部分之上。此时,即使弹出窗口的Z索引大于叠加层的Z索引,弹出窗口的部分仍会出现在叠加层下面。 – wsaxton

0

您需要交换覆盖和弹出的z-index。

你可以给#覆盖一个5的z-index和一个-1的z-index(或者你想使用的任何数字)的.popup。那么你应该很好去。

+0

对不起,我不清楚。我希望弹出窗口位于叠加层之上,叠加层位于页面的其余部分之上。此时,即使弹出窗口的Z索引大于叠加层的Z索引,弹出窗口的部分仍会出现在叠加层下面。 – wsaxton

+0

给#重叠一个不同的背景颜色(如#cccccc)和一个z-index 2.给#popup一个背景颜色:#000; .... color:#fff;和z-index:5 .....在你的HTML中的叠加div上面添加一些文本。分层看起来是否正确?如果是这样,那么你可以删除背景颜色和字体颜色,并保持z索引。 –

+0

哦,你的意思是你想让弹出窗口重叠覆盖层?你可能只需要添加“top:0”;到你的#popup CSS –