我在这里遇到了一些问题,但主要问题是移动响应与下拉菜单。我无法弄清楚我做错了什么。
这是我的HTML:
<div class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
</div><!--nav-header-->
<div class="collapse navbar-collapse">
<ul class="nav nav-pills">
<li><a href="index.html">Home</a></li>
<li><a href="About.html">About</a></li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" data-target="#">Practice <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">A</a></li>
<li><a href="#">B</a></li>
<li><a href="#">C</a></li>
<li><a href="#">D</a></li>
<li><a href="#">E</a></li>
</ul>
</li>
<li><a href="Blog.html">Blog</a></li>
<li><a href="Contact.html">Contact</a></li>
</ul>
</div><!--collapse-->
</div><!--container-->
</div><!--navbar-->
这是我的CSS:
.navbar {
background: black;
position: absolute;
margin-top: 50px;
width: 100%;
border-top: 2px solid black;
border-bottom: 3px solid #4f3838;}
.navbar .nav-pills li {
font-size: 1.2em !important;}
.navbar .nav-pills a {
color: white;
margin: 0 3px 0 3px;}
.navbar .nav-pills a:hover {
color: black;}
.dropdown .dropdown-menu {
background: black;}
我在移动设备上遇到两个问题:首先,在我点击然后取消选中菜单按钮后,它会保持选中状态(点击后显示为灰色而不是黑色),然后是主要信息向下菜单水平显示,下拉列表中的下拉列表垂直显示,造成热点。我不知道我做了什么导致这个或如何解决它。当我查看教程时,示例导航栏基本上与我的相同,它们的下拉行为与预期一致。
我的最后一个问题是,当我选择下拉&#34;练习&#34;我将文本设置为在鼠标悬停时变黑,但因为它是导航丸,所以当它被选中/打开时背景为白色。因此,如果您打开菜单并将鼠标移开,则文本为白色,背景也为白色。是否有针对此的CSS解决方案?
您可以在此处查看代码:http://www.bootply.com/5q1qGfp2c3
如果您进入移动视图并将窗口向下碾压,您可以看到我对下拉菜单的意思。
答案 0 :(得分:0)
添加最新Bootstrap和jQuery JavaScript的脚本链接。这应该可以修复您的移动宽度导航栏下拉列表。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
答案 1 :(得分:0)
您会看到奇怪的行为,因为您使用的是nav-pills而不是默认的navbar元素。请参阅工作示例,了解一些自定义内容的方法。
/***Navbar Background Color, Border Removed ,Border Radius Sqaure***/
.navbar.navbar-custom {
background: black;
margin-top: 50px;
border: none;
border-top: 2px solid black;
border-bottom: 3px solid #4f3838;
border-radius: 0;
}
/***Link Color***/
.navbar.navbar-custom .navbar-nav > li > a {
color: white;
margin: 0 3px 0 3px;
font-size: 1.2em;
}
/***Link Color Hover Statr***/
.navbar.navbar-custom .navbar-nav > li > a:hover {
color: black;
}
/***Link Color Hover Statr***/
.navbar.navbar-custom .navbar-nav > li:hover,
.navbar.navbar-custom .navbar-nav > li:focus {
background: white;
}
/***Link Background and Color Active State***/
.navbar.navbar-custom .navbar-nav > .active,
.navbar.navbar-custom .navbar-nav > .active > a,
.navbar.navbar-custom .navbar-nav > .active > a:hover,
.navbar.navbar-custom .navbar-nav > .active > a:focus {
background: white;
color: black;
}
/***Navbar Brand Link Color***/
.navbar.navbar-custom .navbar-brand {
color: white;
}
/***Dropdown-menu Background Color***/
.navbar.navbar-custom .dropdown-menu {
background: black;
border: none;
}
/***Dropdown-menu Color***/
.navbar.navbar-custom .dropdown-menu > li > a {
color: white;
font-size: 1.2em;
}
/***Dropdown-menu Color Hover and Focus State***/
.navbar.navbar-custom .dropdown-menu > li > a:hover,
.navbar.navbar-custom .dropdown-menu > li > a:focus {
color: black;
background: white;
}
/***Dropdown Background Active State***/
.navbar.navbar-custom .nav li.dropdown.open > .dropdown-toggle,
.navbar.navbar-custom .nav li.dropdown.active > .dropdown-toggle,
.navbar.navbar-custom .nav li.dropdown.open.active > .dropdown-toggle {
background: white;
color: black;
}
/***Toggle Button***/
.navbar.navbar-custom .navbar-header .navbar-toggle {
border: none;
}
/***Toggle Button Hover and Focus State***/
.navbar.navbar-custom .navbar-header .navbar-toggle:hover,
.navbar.navbar-custom .navbar-header .navbar-toggle:focus {
background: white;
border: none;
}
/***Collapse Borders***/
.navbar.navbar-custom .navbar-collapse {
border: none;
}
@media (max-width: 767px) {
.navbar.navbar-custom li.dropdown .dropdown-menu > li > a {
color: white;
background: black;
}
/***Dropdown-menu Color Hover and Focus State***/
.navbar.navbar-custom li.dropdown .dropdown-menu > li > a:hover,
.navbar.navbar-custom li.dropdown .dropdown-menu > li > a:focus {
color: black;
background: white;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-custom">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <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="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a>
</li>
<li><a href="About.html">About</a>
</li>
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">A</a>
</li>
<li><a href="#">B</a>
</li>
<li><a href="#">C</a>
</li>
<li><a href="#">D</a>
</li>
<li><a href="#">E</a>
</li>
</ul>
</li>
<li><a href="Blog.html">Blog</a>
</li>
<li><a href="Contact.html">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>