There are a few problems which you might want to resolve in order to fix this. The first is that your HTML is ambiguous / poorly formed:
<div class="out"><div class="left">
</div>
<div class="right"></div>
My assumption is that what you really mean is:
<div class="out">
<div class="left"></div>
<div class="right"></div>
</div>
(You were missing a closing </div>
)
With this fixed, the easiest solution is actually to pull the shadow out of the underlying tag (the .out
div
), and instead create the shadow as an overlay.
Example:
<div class="out">
<div class="left"></div>
<div class="right"></div>
<div class="shadow"></div>
</div>
With this done, you can easily place the .left
and .right
<div>
elements where you want them, and then force the .shadow
div
to appear on top.
Consider the following CSS (I also normalized your CSS some to reduce repetition):
.out, .shadow {
height: 600px; width: 600px;
}
.out {
background-color: AliceBlue;
position: relative;
}
.shadow {
background: transparent;
-webkit-box-shadow: inset 0px 0px 5px 5px ;
box-shadow: inset 0px 0px 5px 5px;
position: absolute; top: 0; left: 0;
}
.left, .right {
height: 100px; width: 100px;
bottom: 0;
position: absolute;
}
.left {
background-color: green;
left: 0;
}
.right {
background-color: red;
right: 0;
}
Because the .shadow
div
appears last, you don't need any special z-order
in order to get it to appear on-top.
Here is a working cssdesk to demonstrate it in-action.
Edit:
As mentioned in the comments - the original question actually asks for only one of the two boxes to appear under the box-shadow
. If you want one of them to appear above it, simply move that box's HTML tag so that it appears after the .shadow
<div>
, like this:
<div class="out">
<div class="left"></div>
<div class="shadow"></div>
<div class="right"></div>
</div>
This will cause the .right
box (the red one) to appear above the shadow, rather than below - without the need for any z-index
nastiness.
I have updated the cssdesk example to show this version instead.