演示:
http://codepen.io/anon/pen/vLgKC
有关z-index和堆栈上下文以及优先级的更多信息,请参阅我的答案here.
以上,结合了盒子阴影的插图
inset
If not specified (default),the shadow is assumed to be a drop shadow (as if the Box were raised above the content).
The presence of the inset keyword changes the shadow to one inside the frame (as if the content was depressed inside the Box).
Inset shadows are drawn inside the border (even transparent ones),above the
background,but below content.
而负面的传播
spread-radius
This is a fourth value. Positive values will cause the shadow to expand and grow bigger,negative values will cause the
shadow to shrink. If not specified,it will be 0 (the shadow will be the same size as the element).
(两者都是here)
会给你你想要的效果.
因此,您需要更改阴影应用于元素的位置.
所以最终的CSS:
#b {
background: orange;
z-index: 2;
position: relative;
}
#c {
background: red;
-webkit-Box-shadow: inset 0 10px 10px -10px black;
-moz-Box-shadow: inset 0 10px 10px -10px black;
Box-shadow: inset 0 10px 10px -10px black;
z-index: 1;
position: relative;
}
ul {
list-style: none;
margin: 0;
padding: 0;
z-index: 1;
position: relative;
}
li {
display: inline-block;
padding: 2px 5px;
}
.current {
background-color: orange;
z-index: 3;
position: relative;
}
#d {
Box-shadow: 0 0 10px black;
z-index: 2;
}