我希望将Bootstrap 3导航栏折叠到另一个断点处的汉堡菜单,以避免其断行。
当前: 期望的:
我已经尝试粘贴Change Navbar breakpoint in Bootstrap 3.3.2和Change bootstrap navbar collapse breakpoint without using LESS等各种答案中推荐的CSS解决方案。
上面第一个链接的最高答案是:
问题:
body {
background: #f0f0f0;
}
.navbar {
border: none;
}
.dropdown-menu {
background-color: #f5f5f5;
}
.navbar-header {
background-color: #3a7dbb;
}
.collapse.navbar-collapse.js-navbar-collapse {
background-color: #3a7dbb;
}
.navbar-default .navbar-nav > li > a.dropdown-toggle {
font-family: "Oswald",Helvetica,Arial,sans-serif;
font-size: 18px;
color: white;
}
.dropdown > .dropdown-menu > li > a {
font-size: 16px;
}
.glyphicon-shopping-cart:before {
color: white;
}
.navbar .navbar-brand {
padding-top: 0px;
}
.navbar .navbar-brand > img{
height: 100%;
}
.dropdown > .dropdown-menu > li > a:hover {
background-color: white;
}
.navbar-nav > li > .dropdown-menu {
background-color: #f5f5f5;
margin-top: 20px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.navbar-default .navbar-nav > li > a {
/* width: 8em; */
font-weight: bold;
}
.mega-dropdown {
position: static !important;
width: 100%;
}
.mega-dropdown-menu {
padding: 20px 0px;
width: 100%;
box-shadow: none;
-webkit-box-shadow: none;
}
.center {
margin: auto;
}
.mega-dropdown-menu > li > ul {
padding: 0;
margin: 0;
}
.mega-dropdown-menu > li > ul > li {
list-style: none;
}
.mega-dropdown-menu > li > ul > li > a {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571429;
color: #262626;
white-space: normal;
}
.mega-dropdown-menu > li ul > li > a {
font-size: 16px;
}
.mega-dropdown-menu > li ul > li > a:hover,
.mega-dropdown-menu > li ul > li > a:focus {
text-decoration: none;
color: #444;
background-color: white;
}
li.dropdown:hover {
background-color: #c3c1c1;
}
ul.dropdown-menu.mega-dropdown-menu.row {
width: 80%;
left: 0;
right: 0;
margin: 0 auto; /* Centers the element */
}
.mega-dropdown-menu .dropdown-header {
color: #428bca;
font-size: 18px;
font-weight: bold;
}
.mega-dropdown-menu .dropdown-header > a {
color: #428bca;
font-size: 18px;
font-weight: bold;
padding-left: 0;
}
.mega-dropdown-menu form {
margin: 3px 20px;
}
.mega-dropdown-menu .form-group {
margin-bottom: 3px;
}
.navbar-default .navbar-nav .open .dropdown-menu > li > a {
color: black !important;
}
/* .mega-dropdown-menu:before {
content: "";
border-bottom: 15px solid #fff;
border-right: 17px solid transparent;
border-left: 17px solid transparent;
position: absolute;
top: -15px;
left: 285px;
z-index: 10;
}
.mega-dropdown-menu:after {
content: "";
border-bottom: 17px solid #ccc;
border-right: 19px solid transparent;
border-left: 19px solid transparent;
position: absolute;
top: -17px;
left: 283px;
z-index: 8;
} */
.dropdown:hover .dropdown-menu {
display: block;
margin-top: 0; // remove the gap so it doesnt close
}
#main_pnlSiteTemplateHeader {
background-color: white;
padding-left: 0px;
padding-right: 0px;
}
#main_content_Content {
padding-top: 80px;
}
#main_content_TopBanner {
padding-top: 80px;
}
ul.dropdown-menu.mega-dropdown-menu.row {
top: 49px;
}
@media only screen and (min-width: 768px) {
.dropdown:hover > .dropdown-menu {
display: block;
}
.dropdown > .dropdown-toggle:active {
pointer-events: none;
}
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Oswald|Open+Sans:400,400italic,600italic,600">
<!------ Include the above in your HEAD tag ---------->
<div class="">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".js-navbar-collapse">
<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="#"><img src="http://www.hibarnsley.com/wp-content/uploads/2017/06/dummy-logo.png"></a>
</div>
<div class="collapse navbar-collapse js-navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">About<span class="caret"></span></a>
<ul class="dropdown-menu mega-dropdown-menu row">
<li class="col-sm-4">
<ul>
<li class="dropdown-header"><a href="#">Business Relationship Management</a></li>
<li><a href="#">Capability</a></li>
<li><a href="#">Role</a></li>
<li><a href="#">Discipline</a></li>
<li><a href="#">Philosophy</a></li>
</ul>
</li>
<li class="col-sm-4">
<ul>
<li class="dropdown-header"><a href="#">Institute</a></li>
<li class="divider"></li>
<li class="dropdown-header"><a href="#">Policies</a></li>
<li class="divider"></li>
<li class="dropdown-header"><a href="#">Registered Providers</a></li>
<li class="divider"></li>
<li class="dropdown-header"><a href="#">Strategic Alliances</a></li>
</ul>
</li>
<li class="col-sm-4">
<ul>
<li class="dropdown-header"><a href="#">Member-Based Leadership</a></li>
<li class="divider"></li>
<li class="dropdown-header"><a href="#">Board of Directors</a></li>
<li class="divider"></li>
<li class="dropdown-header"><a href="#">Knowledge Team</a></li>
<li class="divider"></li>
<li class="dropdown-header"><a href="#">Executive Council</a></li>
<li class="divider"></li>
<li class="dropdown-header"><a href="#">Council</a></li>
<li class="divider"></li>
<li class="dropdown-header"><a href="#">Regional Ambassadors</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Resources<span class="caret"></span></a>
<ul class="dropdown-menu mega-dropdown-menu row">
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Learning<span class="caret"></span></a>
<ul class="dropdown-menu mega-dropdown-menu row">
</ul>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Programs<span class="caret"></span></a>
<ul class="dropdown-menu mega-dropdown-menu row">
</ul>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Career<span class="caret"></span></a>
<ul class="dropdown-menu mega-dropdown-menu row">
</ul>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Membership<span class="caret"></span></a>
<ul class="dropdown-menu mega-dropdown-menu row">
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown"><a class="dropdown-toggle" href="#">Marketplace<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="/books">Publications</a></li>
<li><a href="/memberships">Memberships</a></li>
<li><a href="/events">Events</a></li>
<li class="divider"></li>
<li><a href="/brm-marketplace">Full Marketplace</a></li>
</ul>
</li>
<li><a href="/brm-cart"><span class="glyphicon glyphicon-shopping-cart"></span></a></li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-question-sign"></span><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">FAQs</a></li>
<li><a href="#">Intellectual Property Request</a></li>
<li><a href="#">Contact BRM Institute</a></li>
</ul>
</li>
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span> Sign Up</a>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
<a href="http://brmi.mpxstage.com/account/login.aspx" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-log-in"></span> Login</a>
</li>
</ul>
</ul>
</div>
</nav>
</div>
谢谢!
答案 0 :(得分:1)
最干净的解决方案是根据需要自定义引导程序库。在引导程序3.3中,这是可能的。 请参考此链接https://getbootstrap.com/docs/3.4/customize/。 请参考变量“ @ grid-float-breakpoint”(导航栏未折叠的位置)。为它设置的默认值为“ @ screen-sm-min”,根据您的要求进行修改,例如“ @ screen-lg-min”。 编译并下载引导程序库,并将其包含在index.html中。 它将以最干净的方式解决您的所有问题。
答案 1 :(得分:0)
请尝试使用此代码
BadName