Here is an example of what I'm trying to accomplish.
The box-shadow
from the upper div
won't appear on top of the div
below it. From what I understand, I need to set the z-index
so it will appear on top and that only works on elements with position: relative;
but it's still not appearing.
What am I doing wrong?
#top {
width: 100%;
height: 100px;
box-shadow: 3px 3px 3px #333;
background-color: blue;
}
#middle {
width: 100%;
height: 200px;
z-index: 0;
position: relative;
background-color: orange;
}
#innerMiddle {
width: 200px;
height: 200px;
margin: 0 auto;
background-color: green;
}
<div id="top">
</div>
<div id="middle">
<div id="innerMiddle">
</div>
</div>
Set the DIV's z-index to one larger than the other DIVs. You'll also need to make sure the DIV has a position other than static set on it, too. position relative and z index set to 999999999999999999999999999999999999999999999999999.
CSS Syntax box-shadow: none|h-offset v-offset blur spread color |inset|initial|inherit; Note: To attach more than one shadow to an element, add a comma-separated list of shadows (see "Try it Yourself" example below).
It's #top
and its box-shadow
that you want to appear on top, so give that position: relative
instead of giving position: relative
to #middle
. There's no need for z-index: 0
.
http://jsfiddle.net/thirtydot/QqME6/1/
#top {
width: 100%;
height: 100px;
box-shadow: 3px 3px 3px #333;
background-color: blue;
position: relative;
}
#middle {
width: 100%;
height: 200px;
background-color: orange;
}
#innerMiddle {
width: 200px;
height: 200px;
margin: 0 auto;
background-color: green;
}
<div id="top">
</div>
<div id="middle">
<div id="innerMiddle">
</div>
</div>
Change your CSS to:
#top {
width: 100%;
height: 100px;
box-shadow: 3px 3px 3px #333;
background-color: blue;
position:relative;
z-index:1;
}
#middle {
width: 100%;
height: 200px;
z-index: 0;
position: relative;
background-color: orange;
}
<div id="top">
</div>
<div id="middle">
<div id="innerMiddle">
</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