我的盒子阴影被图像覆盖

时间:2014-11-02 05:56:46

标签: html css css3

如果你看http://jsfiddle.net/nqugcutn/,你会注意到我的标题上的框阴影被内容覆盖,内容具有图像背景。 (原谅丢失的字体)。如何才能显示框阴影?

/* Header */

.header {
    background: linear-gradient(#ffffff, #f5f5f5);
    width: 100%;
    margin-top: 0;
    height: 75px;
    border-top: 5px solid #1379DB;
    box-shadow: 1px 1px 5px #000;
    z-index: 1;
}

.logoName {
    color: #000;
    font-family: Lobster, sans-serif;
    font-size: 30px;
    margin: 20px 20px;
    float: left;
}

/* Content */

.container {
    background-image: url(http://i.imgur.com/ScGxG2b.png);
    background-size: cover;
    background-color: #242424;
    height: 1000px;
    width: 100%;
    z-index: 2;
}

提前致谢!

1 个答案:

答案 0 :(得分:3)

position: relative;添加到.header div会使框阴影显示在背景图像上方。这是一个演示:



/* Header */

.header {
  background: linear-gradient(#ffffff, #f5f5f5);
  width: 100%;
  margin-top: 0;
  height: 75px;
  border-top: 5px solid #1379DB;
  box-shadow: 1px 1px 5px #000;
  z-index: 1;
  position: relative;
}
.logoName {
  color: #000;
  font-family: Lobster, sans-serif;
  font-size: 30px;
  margin: 20px 20px;
  float: left;
}
.header ul {
  list-style-type: none;
  margin-top: 20px;
  margin-right: 250px;
  float: right;
}
.header ul li {
  display: inline-block;
  font-family: Montserrat, sans-serif;
  color: #333;
  font-size: 20px;
  padding: 10px 10px;
}
.header ul li a {
  font-family: Montserrat, sans-serif;
  color: #333;
  font-size: 20px;
}
.header ul li a:hover,
.header ul li a:active {
  border-bottom: #1379DB solid;
  color: #000;
}
.header ul li a:link {
  text-decoration: none;
}
/* Content */

.container {
  background-image: url(http://i.imgur.com/ScGxG2b.png);
  background-size: cover;
  background-color: #242424;
  height: 1000px;
  width: 100%;
  z-index: 2;
}

<div class="header">
  <h1 class="logoName">Company Name</h1>
  <ul>
    <li><a href="#">Home</a>
    </li>
    <li><a href="/showcase">Showcase</a>
    </li>
    <li><a href="/message">Contact Us</a>
    </li>
  </ul>
</div>
<div class="container">
</div>
&#13;
&#13;
&#13;

<强> jsFiddle demo