我在将 box-shadow 应用于容器时遇到了类似的问题,这是对我有用的解决方案:-
HTML 代码
<div class="graph">
<section>
<div>
<span class="danger" style="height: 29.33333333333333%;">Failed</span>
</div>
<div>
<span class="safe" style="height: 70.66666666666667%;">Sent</span>
</div>
</section>
</div> <!-- END GRAPH -->
CSS 代码
.graph {
width: 280px;
height: 300px;
position: aboslute;
box-shadow: inset 0 0 30px rgba(0,0,0,0.5);
z-index: 999;
}
.graph section {
width: 100%;
height: 100%;
display: table;
text-align: center;
position: relative;
z-index: -1;
background: orange;
margin: 0;
padding: 0;
}
.graph section div {
display: table-row;
position: relative;
}
.graph section span {
display: table-cell;
vertical-align: middle;
position: relative;
z-index: 1;
}
这样,box-shadow 就会覆盖子元素,并且子元素也可以访问。