我试图让我的导航和页脚链接在宽度减小时折叠成切换按钮,但没有使它们具有类“navbar-default”(该类将另一个导航栏添加到我的导航栏并使它看起来很难看。
以下是我标题导航HTML的示例:
<div class="header" id="header-container">
<div class="container" id="header">
<button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#header-collapse-1"><span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<ul class="nav collapse navbar-collapse nav-pills pull-right" id="header-collapse-1">
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/img/resume.pdf" target="_blank">Resume</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
<h3>TITLE</h3>
</div>
</div>
导航按钮消失但没有切换按钮可以打开手风琴。如果有解决方法可以显示切换按钮,请告诉我。
答案 0 :(得分:5)
我能想到的唯一方法是在导航栏中添加一个类,并创建一些规则来覆盖只有该类的元素的导航栏。
考虑添加这两个规则(并根据需要自定义样式): -
.custom-nav-bar.navbar-toggle {
background-color: #ddd; /*Background color for holder*/
}
.custom-nav-bar.navbar-toggle .icon-bar {
background-color: #888; /*Background color for bar in the holder*/
}
并将custom-nav-bar
添加到navbar-toggle
元素
<button class="navbar-toggle collapsed pull-left custom-nav-bar" data-toggle="collapse" data-target="#header-collapse-1">
.custom-nav-bar.navbar-toggle {
background-color: #ddd;
}
.custom-nav-bar.navbar-toggle .icon-bar {
background-color: #888;
}
&#13;
<!DOCTYPE html>
<html>
<head>
<script data-require="jquery@*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script data-require="bootstrap@3.1.1" data-semver="3.1.1" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link data-require="bootstrap-css@3.1.1" data-semver="3.1.1" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="header" id="header-container">
<div class="container" id="header">
<button class="navbar-toggle collapsed pull-left custom-nav-bar" data-toggle="collapse" data-target="#header-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse" id="header-collapse-1">
<ul class="nav navbar-nav nav-pills pull-left " >
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/img/resume.pdf" target="_blank">Resume</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
&#13;