I'm creating a sidebar block with an inset shadow. I want the shadow to appear on top of the .block-title element, but the shadow is rendered under it.
You can see the problem here: JSFiddle
This is my css:
.block{
width:250px;
-webkit-box-shadow: inset 7px 0 10px -5px rgba(0,0,0,0.3);
-moz-box-shadow: inset 7px 0 10px -5px rgba(0,0,0,0.3);
box-shadow: inset 7px 0 10px -5px rgba(0,0,0,0.3);
border:1px solid gray;
}
.block .block-title{
background:#dedede;
padding:5px;
}
.block .block-title span{
color:#333;
font-size:14px;
text-align:center;
}
.block .block-content{
padding:10px;
}
You can set the box shadow on top of the children using an absolutely positioned pseudo element (::before). Use poiner-events: none on the pseudo element to allow interaction with the elements under it.
body {
margin: 10px;
}
.block {
position: relative;
width: 250px;
border: 1px solid gray;
}
.block::before {
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
box-shadow: inset 7px 0 10px -5px rgba(0, 0, 0, 0.3);
pointer-events: none;
content: '';
}
.block .block-title {
background: #dedede;
padding: 5px;
}
.block .block-title span {
color: #333;
font-size: 14px;
text-align: center;
}
.block .block-content {
padding: 10px;
}
<div class="block">
<div class="block-title">
<span>Lorem ipsum dolor</span>
</div>
<div class="block-content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam efficitur elit quis auctor sollicitudin. Aenean est lorem, ornare in laoreet sed, lobortis ac libero. Phasellus dignissim imperdiet varius.
</div>
</div>
What is happening here is that .block-title is covering the shadow effect. You could make the effect appear a bit more if you added opacity, or gave the color an rgba-value.
I changed the hexidecimal color to rgba in my example.
JS-Fiddle: https://jsfiddle.net/4fkfdxn6/4/
html
<div class="block">
<div class="block-title">
<span>Lorem ipsum dolor</span>
</div>
<div class="block-content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam efficitur elit quis auctor sollicitudin. Aenean est lorem, ornare in laoreet sed, lobortis ac libero. Phasellus dignissim imperdiet varius.
</div>
</div>
css
body{
margin:10px;
}
.block{
width:250px;
-webkit-box-shadow: inset 7px 0 10px -5px rgba(0,0,0,0.3);
-moz-box-shadow: inset 7px 0 10px -5px rgba(0,0,0,0.3);
box-shadow: inset 7px 0 10px -5px rgba(0,0,0,0.3);
border:1px solid gray;
}
.block .block-title{
background:rgba(0, 0, 0, 0.4); /*changed this value*/
padding:5px;
}
.block .block-title span{
color:#333;
font-size:14px;
text-align:center;
}
.block .block-content{
padding:10px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With