Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS box-shadow appears only with margin

So, my website has a header and a div containing Revolution Slider immediately after it. I'm trying to add a box-shadow below the header - and above the slider. But it doesn't work, unless I also add margin-bottom to the header - but that renders the whole exercise moot.

This is the code:

#header {
  display:block;
  min-height: 99px;
  background: #FFFFFF;
  border-top: 3px solid #8dddcd;
  border-bottom: 1px solid #ecf0f1;
  line-height: 99px;
  box-shadow: 0 10px 10px 10px rgba(0,0,0,0.3);
}
#rev {
  position: relative;
}
<div id="header"></div>
<div id="rev">the slider</div>

Could someone help me figure out what's causing this?

like image 411
zkvvoob Avatar asked Mar 26 '15 15:03

zkvvoob


People also ask

How do I change the shadow position in CSS?

These are two <length> values to set the shadow offset. <offset-x> specifies the horizontal distance. Negative values place the shadow to the left of the element. <offset-y> specifies the vertical distance.

How do you get a box shadow on the bottom only?

To display the shadow at the bottom of the image, the “box-shadow” property is used. For this purpose, offset-x is set as “0”, offset-y is any positive value, and the color you want to display is also set.


2 Answers

See the following questions:

  • Does css border-shadow add to an element's size
  • Is css box-shadow part of element's box model?

According to the box-shadow spec:

An outer box-shadow casts a shadow as if the border-box of the element were opaque. The shadow is drawn outside the border edge only

So if you don't want overlap, you'll have to add the margin youself

#header {
  box-shadow: 5px 5px 5px 5px rgba(0,0,0,0.3);
  margin-bottom: 10px;
}
#slider {
  position: relative;
}
<div id="header">Header</div>
<div id="slider">Slider</div>
like image 157
KyleMit Avatar answered Nov 04 '22 10:11

KyleMit


Actually, the issue turned out to be related to z-index properties of the different divs. With some tweaking I managed to get it all sorted out without using any margin.

Anyway, thank you all for your time and help!

like image 5
zkvvoob Avatar answered Nov 04 '22 11:11

zkvvoob