[英]Background Image with Transparent Overlay
I've added a transparent mask on my background image.我在我的背景图片上添加了一个透明的蒙版。 The 1st layer will be my navigation bars, contents.第一层将是我的导航栏,内容。 Second layer will be the transparent mask, and last layer will be the background image.第二层将是透明蒙版,最后一层将是背景图像。 I manage to make my navigation bar to stay in front of the transparent mask, but now I'm unable to click on the navigation.我设法让我的导航栏停留在透明蒙版前面,但现在我无法点击导航。
HTML: 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: 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;
}
I suggest to not use negative z-index in this scenario, as it will make things a lot more complicated.我建议不要在这种情况下使用负 z-index,因为它会使事情变得更加复杂。 Instead remove all the z-indexes and set the position of your list and headline to relative.取而代之的是删除所有 z 索引并将列表和标题的位置设置为相对位置。
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; }
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.