你好,我正在尝试创建一个“粘性”导航栏,但是在滚动后,页面下方的内容会覆盖导航栏。我尝试为导航应用z-index,但不确定为什么它不起作用。非常感谢任何帮助!
HTML
<!-- Start Header -->
<header classs="parallax">
<section id="stickynav">
<div class="container-responsive">
<div class="row">
<div class="col-lg-4">
<h1>Title</h1>
</div>
<div class="col-lg-6">
Content
</div>
<div class="col-lg-2">
Content
</div>
</div>
</div>
</section>
</header>
<!-- End Header -->
<!-- Start Main -->
<section id="main">
<div class="container">
<h2>About Us</h2>
</div>
</section>
<!-- End Main -->
CSS
header {
width: 100%;
height: 90%;
background-image: url('../images/slider/accounting-banner.jpg');
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-clip-path: polygon(0 0, 100% 0, 100% 100%, 0 90%);
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 90%);
color: #fff;
}
section#stickynav {
position: fixed;
z-index: 9999;
height: 12%;
width: 100%;
padding-top: 1%;
padding-left: 2%;
padding-bottom: 1%;
padding-right: 2%;
}
.stickystyle {
background-color: #FFF;
-webkit-box-shadow: 0px 1.5px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 1.5px 5px 0px rgba(0,0,0,0.75);
box-shadow: 0px 1.5px 5px 0px rgba(0,0,0,0.75);
color: #000;
}
section#main {
margin-top: -2.5%;
position: relative;
z-index: -1;
}
JS
<script>
var sn = $("#stickynav");
$(window).scroll(function() {
if($(this).scrollTop() > 100) {
sn.addClass("stickystyle");
} else {
sn.removeClass("stickystyle");
}
});
</script>
感谢您的提前帮助。