本文介绍了在儿童上方的盒子阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取插图CSS3 box-shadow
呈现在其子元素之上?
How do I get an inset CSS3 box-shadow
to render on top of its children elements?
问题:
HTML:
<div id="chatroom">
<div class="chatmessage"><b>User 1:</b>Test</div>
<div class="chatmessage"><b>User 2:</b>Test</div>
<div class="chatmessage"><b>User 1:</b>Test</div>
<div class="chatmessage"><b>User 2:</b>Test</div>
</div>
CSS:
#chatroom{
border: 1px solid #CCC;
height: 135px;
font-size: 0.75em;
line-height: 1.2em;
overflow: auto;
-moz-box-shadow: inset 0 0px 4px rgba(0,0,0,.55);
-webkit-box-shadow: inset 0 0px 4px rgba(0,0,0,.55);
}
.chatmessage{
padding: 4px 2px;
}
.chatmessage b{
margin-right: 2px;
}
.chatmessage:nth-child(2n) {
background: #EEE;
}
推荐答案
不能直接从CSS完成.(如果它位于重叠元素上方,则不是阴影)
cant be done directly from css.. (it is not shadow if it goes above overlapping elements)
您需要通过添加div来重新整理html(或使用 miguelcobain的建议的伪元素答案)以覆盖阴影和CSS,以使新的div具有阴影.
you would need to rework your html a bit by adding a div (or use a pseudo element as suggested by miguelcobain's answer) to overlay the shadow and your CSS to make the new div have the shadow..
#chatroom {
border: 1px solid #CCC;
height: 135px;
font-size: 0.75em;
line-height: 1.2em;
overflow: auto;
position: relative;
}
.shadow {
position: absolute;
left: 0px;
top: 0px;
right: 0px;
bottom: 0px;
-moz-box-shadow: inset 0 0px 4px rgba(0, 0, 0, .55);
-webkit-box-shadow: inset 0 0px 4px rgba(0, 0, 0, .55);
box-shadow: inset 0 0px 4px rgba(0, 0, 0, .55);
}
.chatmessage {
padding: 4px 2px;
}
.chatmessage b {
margin-right: 2px;
}
.chatmessage:nth-child(2n) {
background: #EEE;
}
<div id="chatroom">
<div class="chatmessage"><b>User 1:</b>Test</div>
<div class="chatmessage"><b>User 2:</b>Test</div>
<div class="chatmessage"><b>User 1:</b>Test</div>
<div class="chatmessage"><b>User 2:</b>Test</div>
<div class="shadow"></div>
</div>
这篇关于在儿童上方的盒子阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!