html - 带有背景图片的导航上的 CSS 投影

标签 html css box-shadow

我在页面顶部有一个导航栏,它有一个 box-shadow,但它似乎不适用于下面的 section 元素带有背景网址。如果我注释掉 background 属性,阴影就会很明显。

这是代码笔: http://codepen.io/himmel/pen/ByxeGR

这是标记:

<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>

这是 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;
  }
}

如何让投影出现在背景图片上?

最佳答案

您可以将 position: relative; 添加到您的 .header 样式中。

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

关于html - 带有背景图片的导航上的 CSS 投影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28724662/

相关文章:

javascript - CSS 框阴影重叠

javascript - 如何制作粘性元素 'float'

javascript - 如何实现jquery验证

javascript - 图像未加载到 IE 的 Angular 页面中

css - 自托管字体在 Gatsby 和 Safari 中不起作用

html - 我可以在宽度和高度为 0 的 div 上有一个圆框阴影吗

css - 无法弄清楚为什么图像在 ie7 中堆叠

css - 无法删除已访问链接上的框阴影 - 应用了两次

android - 水平居中包装器 DIV 在 Android 中不起作用

css - 如何理解 MDN 上描述的关于 box-shadow 的插值?