Search code examples
htmlcssbox-shadow

CSS Drop-Shadow on nav with background image


I've got a navigation bar at the top of the page that has a box-shadow, but it doesn't seem to apply to the section element below with a background url. If I comment out the background attribute, the drop shadow is apparent.

Here is the codepen: http://codepen.io/himmel/pen/ByxeGR

Here is the markup:

<div class="header">
  <span class="brand">BRAND</span>
  <ul class="link">
    <li>Home</li>
    <li>About</li>
    <li>Contact</li>
  </ul>
</div>

<div class="blog-container">
  <section>

  </section> 
</div>

And here is the CSS:

body {
  margin: 0;
}

.header {
  display: flex;
  align-items: center;
  font-family: 'Nunito';
  width: 100%;
  background-color: white;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
  height: 4em;
  .brand {
    font-size: 1.3em;
    padding-left: 1em;
  }
  .link {
    display: flex;
    list-style-type: none;
    flex: 1 auto; // stretch to end of width
    justify-content: flex-end;
    margin: 0;
    font-size: 1.3em;
    li {
      padding-right: 1em;
    }
  }
}

.blog-container {
  display: flex;
  flex-flow: column wrap;
  background: url(https://unsplash.imgix.net/photo-1414490929659-9a12b7e31907?q=75&fm=jpg&s=f838066e7aa9eab9d1ccc28fd5ec9574) no-repeat center center fixed;
  background-size: cover;
  section {
    height: 20em;
  }
}

How can I get the drop shadow to appear over the background image?


Solution

  • You could add position: relative; to your .header style.

    http://codepen.io/anon/pen/YPLoGN