背景图像与透明覆盖

时间:2017-01-15 14:37:12

标签: html css

我在背景图片上添加了透明蒙版。第一层将是我的导航栏,内容。第二层将是透明蒙版,最后一层将是背景图像。我设法让我的导航栏留在透明蒙版前面,但现在我无法点击导航。

HTML:

<body>
    <div id="top">
        <div id="mask"></div>
        <ul>
            <li><a href="index.html">RACHEL LIM</a></li>
            <li style="float:right"><a href="contact.html">CONTACT</a></li>
            <li style="float:right"><a href="gallery.html">GALLERY</a></li>
            <li style="float:right"><a href="aboutMe.html">ABOUT ME</a></li>
            <li style="float:right"><a class="active" href="index.html">HOME</a></li>
        </ul>

        <h1>I'M A CAT LOVER.</h1>
    </div>
</body>

CSS:

body {
    font-family:Calibri;
    font-size:18px;
    margin:0px;
}

#top{
    background-image:url(https://static1.squarespace.com/static/5376a044e4b0cf50765bdde1/t/5377554ae4b0aefc671d7dcc/1400329549490/typewriter.jpg);
    background-size: 100%;
    position:relative;
    height:100vh;
    z-index:-10;
}

#mask{
    position:absolute;
    background-color:rgba(0,0,0,0.4);
    height:100%;
    width:100%;
    z-index:-5;
}

ul {
    list-style-type: none;
    margin:0;
    padding:0;
    overflow:hidden;
}

li {
    float:left;
    padding:20px;
}

li a {
    display:block;
    color:#EDECEA;
    text-align:center;
    padding:14px 16px;
    text-decoration: none;
}

li a:hover {
    color: white;
}

.active{
    color: white;
}

h1{
    font-size:100px;
    color:white;
    text-align:center;
}

1 个答案:

答案 0 :(得分:1)

我建议不要在这种情况下使用负z-index,因为它会使事情变得复杂得多。而是删除所有z索引并将列表和标题的位置设置为相对位置。

&#13;
&#13;
body {
  font-family: Calibri;
  font-size: 18px;
  margin: 0px;
}
#top {
  background-image: url(https://static1.squarespace.com/static/5376a044e4b0cf50765bdde1/t/5377554ae4b0aefc671d7dcc/1400329549490/typewriter.jpg);
  background-size: 100%;
  position: relative;
  height: 100vh;
  /*z-index: -10;*/
}
#top > * {
  position: relative;
}
#mask {
  position: absolute;
  background-color: rgba(0, 0, 0, 0.4);
  height: 100%;
  width: 100%;
  /*z-index: -5;*/
}
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
li {
  float: left;
  padding: 20px;
}
li a {
  display: block;
  color: #EDECEA;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
li a:hover {
  color: white;
}
.active {
  color: white;
}
h1 {
  font-size: 100px;
  color: white;
  text-align: center;
}
&#13;
<div id="top">
  <div id="mask"></div>
  <ul>
    <li><a href="index.html">RACHEL LIM</a>
    </li>
    <li style="float:right"><a href="contact.html">CONTACT</a>
    </li>
    <li style="float:right"><a href="gallery.html">GALLERY</a>
    </li>
    <li style="float:right"><a href="aboutMe.html">ABOUT ME</a>
    </li>
    <li style="float:right"><a class="active" href="index.html">HOME</a>
    </li>
  </ul>

  <h1>I'M A CAT LOVER.</h1>
</div>
&#13;
&#13;
&#13;