[英]How can I make box-shadow appear above a div?
Here is an example of what I'm trying to accomplish.这是我要完成的示例。
The box-shadow
from the upper div
won't appear on top of the div
below it.来自上部div
的box-shadow
不会出现在它下面的div
的顶部。 From what I understand, I need to set the z-index
so it will appear on top and that only works on elements with position: relative;
据我了解,我需要设置z-index
以便它出现在顶部并且仅适用于具有position: relative;
but it's still not appearing.但它仍然没有出现。
What am I doing wrong?我究竟做错了什么?
#top { width: 100%; height: 100px; box-shadow: 3px 3px 3px #333; background-color: blue; } #middle { width: 100%; height: 200px; z-index: 0; position: relative; background-color: orange; } #innerMiddle { width: 200px; height: 200px; margin: 0 auto; background-color: green; }
<div id="top"> </div> <div id="middle"> <div id="innerMiddle"> </div> </div>
It's #top
and its box-shadow
that you want to appear on top, so give that position: relative
instead of giving position: relative
to #middle
. 它是#top
和它的box-shadow
,你想要出现在顶部,所以给出那个position: relative
而不是给position: relative
对于#middle
。 There's no need for z-index: 0
. 不需要z-index: 0
。
http://jsfiddle.net/thirtydot/QqME6/1/ http://jsfiddle.net/thirtydot/QqME6/1/
Change your CSS to: 将您的CSS更改为:
#top {
width: 100%;
height: 100px;
box-shadow: 3px 3px 3px #333;
background-color: blue;
position:relative;
z-index:1;
}
#middle {
width: 100%;
height: 200px;
z-index: 0;
position: relative;
background-color: orange;
}
You must use position: relative in upper div not below div你必须使用 position: relative in upper div not below div
#top { width: 100%; height: 100px; box-shadow: 3px 3px 3px #333; background-color: blue; position: relative; } #middle { width: 100%; height: 200px; z-index: 0; /* position: relative; */ background-color: orange; } #innerMiddle { width: 200px; height: 200px; margin: 0 auto; background-color: green; }
<div id="top"></div> <div id="middle"> <div id="innerMiddle"></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.