所以我正在尝试创建一个具有粘性Navbar和Parallax Effect的网页。它有两个部分:第一部分是图片,下部是一些文字。导航栏仅在文本部分中可见。
不幸的是,当我向下滚动到文本部分时,导航栏就像在图片下面然后弹出一样。如果有人可以帮我解决这个问题(第一次制作网页),将不胜感激!
body {
height: 100%;
overflow: auto;
margin: 0;
padding: 0;
line-height: 1.5;
background-color: white;
font-family: "Trebuchet MS", Helvetica, sans-serif;
}
.container {
width: 80%;
margin: 0 auto;
}
header {
position: fixed;
background: #f4f4f4;
width: 100%;
height: 15%;
/* padding: 0px 30px;*/
box-sizing: border-box;
}
.name {
float: left;
width: 180px;
padding-right: 150px;
}
nav {
width: 100%;
height: 50px;
top: 0;
padding: 15px 0px;
color: black;
text-decoration: none;
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
}
nav li {
display: inline-block;
margin-left: 10px;
margin-top: 0px;
position: relative;
padding: 20px;
}
nav ul li a {
color: black;
text-decoration: none;
text-transform: uppercase;
font-family: "Trebuchet MS", Helvetica, sans-serif;
transition: .4s;
}
<header>
<nav>
<div class="container">
<div class="name">
<img src="logoimg.png> </img>
</div>
<ul>
<li><a href=" # " class="sec1 "> Home</a> </li>
<li><a href="# " class="sec2 "> Who we are</a> </li>
<li><a href="# " class="sec3 "> What we do</a> </li>
<li><a href="# " class="sec4 "> Our projects</a> </li>
<li><a href="# " class="sec5 "> Contact us</a> </li>
</ul>
</nav>
</header>
答案 0 :(得分:0)
将z-index
添加到CSS for nav:
nav {
width: 100%;
height:50px;
top: 0;
padding:15px 0px;
color: black;
text-decoration: none;
z-index: 20
}