[英]Background Image with Transparent Overlay
我在我的背景圖片上添加了一個透明的蒙版。 第一層將是我的導航欄,內容。 第二層將是透明蒙版,最后一層將是背景圖像。 我設法讓我的導航欄停留在透明蒙版前面,但現在我無法點擊導航。
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;
}
我建議不要在這種情況下使用負 z-index,因為它會使事情變得更加復雜。 取而代之的是刪除所有 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.