问题1: 我希望将导航栏粘贴覆盖在背景颜色和顶部之上。 div的背景图片( top-banner ),现在当我向下滚动时。背景颜色将覆盖我的导航栏词缀。
如何实现我的导航栏将在div类顶部横幅的背景颜色之上。
另外还有一个问题是我的导航栏本身有剩余边距,当我添加数据间谍附加功能时,导航栏稍微向右移动,导致左边有空白区域,当我将屏幕重新缩放到较小设备大小,导航栏折叠菜单是不可点击的,除非我略微点击到最右边,然后切换菜单。我不确定为什么词缀会有这样的问题。我该如何解决呢?
感谢您帮助解决此问题!!
以下是我的代码
<html>
<head>
<title>Demo</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
.navbar-header,
.navbar-brand {
line-height: 100px;
height: 100px;
padding-top: 0;
}
.affix .navbar-default {
position: fixed !important;
top: 0 !important;
width: 100% !important;
background-color: #957595 !important;
}
.affix {
width: 100% !important;
}
@media screen and (min-width: 768px) {
.navbar-header {
padding-left: 200px;
text-align: center;
}
}
.top-banner{
background-color: #b0c4de;
background-image: url("bi-uk-office7-2.jpg");
background-repeat: no-repeat;
background-position: right top;
}
</style>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<!-- Static navbar -->
<div id="nav" data-spy="affix">
<nav class="navbar navbar-default" style="background-color:black;background: rgba(0,0,0,0.9);">
<div class="container-fluid">
<div class="navbar-header header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="#"><font color="white">Link 1</font></a></li>
<li><a href="/list"><font color="white">Link 2</font></a></li>
<li><a href="/list"><font color="white">Link 3</font></a></li>
</div><!--/.nav-collapse -->
</div>
</nav>
</div>
<section>
<div class="col-xs-12">
<div class="top-banner">
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
Hello world<br/>
<hr>
</div>
</div>
</section>
</div>
</body>
</html>
答案 0 :(得分:3)
将z-index
添加到您的#nav
,如下所示,并将margin-left
属性添加到同一位置以保持极左,因为它正在从其父{{1}填充}}
container-fluid