我的html页面顶部有一个固定的横幅。当我向下滚动时,想法是将身体放在顶部的横幅下方。
除了我在' col-xs-4'内的图标外,它工作得很好。类。 这些图标(或者我在col-xs-4课程中放置的内容)似乎超越了顶部横幅。
如何更新此内容,以便横幅始终位于首位。
此处链接指向codepen
下面是html代码:
<html>
<head>
<title>hello</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<style>
.navbar {
padding-top: 15px;
padding-bottom: 15px;
border: 0;
border-radius: 0;
margin-bottom: 0;
font-size: 12px;
letter-spacing: 5px;
position:fixed;
width:100%;
background-color:white;
}
.container-fluid {
padding-top: 70px;
padding-bottom: 70px;
}
</style>
</head>
<body id="top">
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header myNavbar">
<a class="navbar-brand" href="#top">HOME</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mainNavBar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse myNavbar" id="mainNavBar">
<ul class="nav navbar-nav navbar-right">
<li><a href="#about">ABOUT</a>
</li>
<li><a href="#connect">CONNECT</a>
</li>
<li><a href="#projects">PROJECTS</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid bg-1 text-center">
<h3>hello world</h3>
<h3 style="color:lightblue;">say something...</h3>
</div>
<div id="connect">
<div class="container-fluid bg-3 text-center">
<h3>Connect</h3>
<div class="row">
<div class="col-xs-4">
<p>
<a href="#" id="linkedIn" target="_blank" class="social-btn"><i class="fa fa-linkedin fa-lg"></i></a>
</p>
</div>
<div class="col-xs-4">
<p>
<a href="#" id="github" target="_blank" class="social-btn"><i class="fa fa-github fa-lg"></i></a>
</p>
</div>
<div class="col-xs-4">
<p>
<a href="#" id="stackOverflow" target="_blank" class="social-btn"><i class="fa fa-stack-overflow fa-lg"></i></a>
</p>
</div>
</div>
<div class="row">
<div class="col-xs-4">
<p>
<a href="#" id="instagram" target="_blank" class="social-btn"><i class="fa fa-instagram fa-lg"></i></a>
</p>
</div>
<div class="col-xs-4">
<p>
<a href="#" id="medium" target="_blank" class="social-btn"><i class="fa fa-medium fa-lg"></i></a>
</p>
</div>
<div class="col-xs-4">
<p>
<a href="#" id="codepen" target="_blank" class="social-btn"><i class="fa fa-codepen fa-lg"></i></a>
</p>
</div>
</div>
</div>
</div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>
答案 0 :(得分:2)
只需将此添加到您的css:
.navbar-default {
z-index: 1;
}
更新了 CodePen Demo
您需要设置z-index
,以便您的固定导航栏显示在其他元素的前面。
以下是z-index
上的一些有用的文档/文章: