I don't understand why, but an inset box shadow is beneath my content.
Here's an example:
div {
box-shadow:inset 0 0 10px black;
height:300px;
color:red;
}
<div>
a
</div>
http://jsfiddle.net/MAckM/
You see the a
is on top of the box shadow.
How can I get the box shadow to be on top of the a
?
Use the box-shadow Property to Set the Bottom Box Shadow in CSS. We can use the box-shadow property to set the shadow only at the bottom of the box. The box-shadow property sets the shadow of the selected element.
The presence of the inset keyword changes the shadow to one inside the frame (as if the content was debossed inside the box). Inset shadows are drawn inside the border (even transparent ones), above the background, but below content. <offset-x> <offset-y> These are two <length> values to set the shadow offset.
Note: By default, the shadow generates outside the box but by the use of inset we can create the shadow inside the box. Syntax: box-shadow: h-offset v-offset blur spread color | inset; Approach: To give the inset shadow to an element, we will use the box-shadow property.
Using transforms on the box-shadow (& transform ) property, we can create the illusion of an element moving closer or further away from the user.
You need to make a new element inside the div, with absolute positioning and height and width of 100%, then give that element the box shadow.
div {
height:300px;
color:red;
position:relative;
}
div div {
box-shadow:inset 0 0 10px black;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
<div>
<div></div>
a
</div>
Edit:
Alternatively, you can use a pseudo element:
div {
height:300px;
color:red;
position:relative;
}
div:before {
content:'';
display:block;
box-shadow:inset 0 0 10px black;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
<div>
a
</div>
This answer offers the most straightforward solution via a minimal example and addresses the issue of scrolling.
Unfortunately there is no way to avoid an extra wrapping div
(due to box-shadow
layering).
.container {
position: relative;
}
.container::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
box-shadow: inset 0 0 9px 3px yellow;
pointer-events: none;
}
.items {
height: 100px;
overflow: scroll;
}
<div class="container">
<div class="items">
<div class="item">One</div>
<div class="item">Two</div>
<div class="item">Three</div>
<div class="item">Four</div>
<div class="item">Five</div>
<div class="item">Six</div>
<div class="item">Seven</div>
<div class="item">Eight</div>
<div class="item">Nine</div>
<div class="item">Ten</div>
<div class="item">Eleven</div>
<div class="item">Twelve</div>
</div>
</div>
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