21

I have a box shadow on a div that i want to stick out like a bar over the next div on the page, but when the next div has a background or background image, it won't show up. is there a way of the shadow showing over the next element even though they are both "position:initial;" http://jsfiddle.net/2u4Lvyn0/2/ so the shadow should overlook the blue box below it

HMTL

<div class="background-image-div"></div>
<div class="box-shadow-div"></div>
<div class="background-image-div"></div>

CSS

.box-shadow-div{
    height:100px;
    background:orange;
    -webkit-box-shadow: 0px 3px 3px 15px rgba(0,0,0,1);
    -moz-box-shadow: 0px 3px 3px 15px rgba(0,0,0,1);
    box-shadow: 0px 3px 3px 15px rgba(0,0,0,1);
}

.background-image-div{
    height:100px;
    background:blue;
    border:1px solid yellow;
}

I've seen a lot of posts on 'inset box-shadow' not working with it's own divs background image but couldn't find anything about just regular sibling divs.

MintWelsh
  • 1,199
  • 13
  • 22

2 Answers2

40

Adding position:relative; will fix it. Though, it may affect other CSS tweaks you already have.

http://jsfiddle.net/2u4Lvyn0/5/

KidBilly
  • 3,408
  • 1
  • 26
  • 40
2

Purest way to create a new stacking context would be to use css property isolation: isolate;

https://jsfiddle.net/mgfyz1j9/2/

Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/isolation

Malolan
  • 53
  • 5