我试图让菜单项消失,然后转移到第二行,并且当我调整浏览器大小时菜单项消失后立即弹出3栏菜单。 http://jsfiddle.net/qwwru7eh/
到目前为止,我尝试使用display none和display:block with inline css style tags来设置媒体查询样式:
我将Bootstrap的问题与以下代码隔离开来,但是我无法通过样式化获得所需的效果:
@media(min-width:872px){。navbar-toggle { display:none; }}
@media(max-width:871px){。navbar-nav .open .dropdown-menu { 位置:静态; float:none;显示:无; 宽度:自动; margin-top:0; 背景颜色:透明; 边界:0; -webkit-box-shadow:none; box-shadow:none; } .navbar-nav .open .dropdown-menu> li> a,.navbar-nav .open .dropdown-menu .dropdown-header { 填充:5px 15px 5px 25px; } .navbar-nav .open .dropdown-menu> li>一个 { 行高:20px; } .navbar-nav .open .dropdown-menu> li> a:悬停,.navbar-nav .open .dropdown-menu> li> a:焦点{ background-image:none; }}
HTML:
<nav class="container-fluid navbar navbar-inverse navbar-static-top">
<div class="container-fluid">
<!--Logo!-->
<div class="navbar-header">
<a href="#" class="navbar-brand">THE LOGO</a>
<!--Toggle Button 3 Lines -->
<button type="button" class="navbar-toggle customtogglebtn" data-toggle="collapse" data-target="#mainNavBar">
<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
</div>
<!--Navigation Menu Items!-->
<div class="collapse navbar-collapse" id="mainNavBar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Menu</a></li>
<li><a href="#">Download</a></li>
<li><a href="#">Team</a></li>
<li><a href="#">Timeline</a></li>
<li><a href="#">Contact</a></li>
<!--Dropdown Menu Item with Options!-->
<li class="dropdown">
<a href="dropdown" class="dropdown-toggle" data-toggle="dropdown">My Profile<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Friends</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">Notifications</a></li>
<li><a href="#">My Timeline</a></li>
<li><a href="#">Log Out</a></li>
</ul>
</li>
</ul>
<!--Right-Align Menu Items!-->
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Logout</a></li>
</ul>
</div>
</div>
</nav>
<!--Page Content -->
<div class="container-fluid belowstatic" style="height:1000px; background:#333; bottom:0;">
静态导航栏
CSS:
body { padding-top: 51px;}
.navbar-toggle { outline:none; border:none; margin-right:-5px; background:none;}
.navbar-static-top {
top: 0;
position: fixed;
left: 0;
right: 0;
margin: 0 auto;
z-index: 1;
}
如果有人知道设置引导菜单项元素的最佳方式,请告诉我如何操作,并告诉我关于样式引导元素的最佳实践。谢谢!
答案 0 :(得分:0)
您有几个选项,第一个选项是减少使用此媒体查询可以执行的菜单项周围的填充:
@media (min-width: 768px) {
.navbar-nav>li>a {
padding:15px 10px;
}
}
如果您不想更改填充,另一个选项是缩小字体大小:
body {
padding-top: 51px;
font-size:13px;
}
答案 1 :(得分:0)
您只需要链接jquery。您的菜单将正常工作。我正在向您发送代码以及链接。如果有任何更改,请告诉我。
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
body {
padding-top: 51px;
}
.navbar-toggle {
outline: none;
border: none;
margin-right: -5px;
background: none;
}
.navbar-static-top {
top: 0;
position: fixed;
left: 0;
right: 0;
margin: 0 auto;
z-index: 1;
}
@media (max-width: 991px) {
.navbar-header {
float: none;
}
.navbar-left,
.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none !important;
}
.navbar-nav {
float: none !important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in {
display: block !important;
}
}
</style>
</head>
<body>
<nav class="container-fluid navbar navbar-inverse navbar-static-top">
<div class="container-fluid">
<!--Logo!-->
<div class="navbar-header">
<a href="#" class="navbar-brand">THE LOGO</a>
<!--Toggle Button 3 Lines -->
<button type="button" class="navbar-toggle customtogglebtn" data-toggle="collapse" data-target="#mainNavBar">
<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
</div>
<!--Navigation Menu Items!-->
<div class="collapse navbar-collapse" id="mainNavBar">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Menu</a></li>
<li><a href="#">Download</a></li>
<li><a href="#">Team</a></li>
<li><a href="#">Timeline</a></li>
<li><a href="#">Contact</a></li>
<!--Dropdown Menu Item with Options!-->
<li class="dropdown">
<a href="dropdown" class="dropdown-toggle" data-toggle="dropdown">My Profile<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Friends</a></li>
<li><a href="#">Settings</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">Notifications</a></li>
<li><a href="#">My Timeline</a></li>
<li><a href="#">Log Out</a></li>
</ul>
</li>
</ul>
<!--Right-Align Menu Items!-->
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Logout</a></li>
</ul>
</div>
</div>
</nav>
<!--Page Content -->
<div class="container-fluid belowstatic" style="height:1000px; background:#333; bottom:0;">
<center>
<h1 style="color:#fff;">Static Navigationbar</h1>
</center>
</div>
<!--End container-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>