我有一个自定义导航栏,我通过使用每个链接的单独div来隔开链接。当宽度<1时768px折叠的链接间隔非常不规则,我想在保留未折叠版本的CSS的同时更正此CSS。
<body>
<nav class="navbar">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#collapse-menu">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<%= link_to("Brand Name", root_path, { :class => "navbar-brand logo" }) %>
</div>
<div class="collapse navbar-collapse" id="collapse-menu">
<ul class="nav navbar-nav middle-left">
<li><%= link_to("About", about_path, { :class => "nav-link-custom" }) %></li>
</ul>
<ul class="nav navbar-nav middle-right">
<li><%= link_to("Help", help_path, { :class => "nav-link-custom" }) %></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a class="nav-link-custom" href="#">Sign In</a></li>
</ul>
</div>
</div>
</nav>
<%= yield %>
</body>
/* Navbar */
.logo:hover {
background: none;
}
.nav > li > a:hover {
background: none;
}
.middle-left {
margin-left: 25%;
}
.middle-right {
margin-left: 10%;
}
.navbar-toggle {
background: white;
border: thin solid gray;
}
.icon-bar {
background: gray;
}
^我拍了这张截图,因为我无法使用这个小提琴。
^我拍了这张截图,因为我无法使用这个小提琴。
答案 0 :(得分:2)
只需使用媒体查询,您的导航就会生成默认的移动导航。
/* Navbar */
.navbar .logo:hover {
background: none;
}
.navbar .nav > li > a:hover {
background: none;
}
.navbar .navbar-toggle {
background: white;
border: thin solid gray;
}
.navbar .icon-bar {
background: gray;
}
@media (min-width: 768px) {
.navbar .middle-left {
margin-left: 25%;
}
.navbar .middle-right {
margin-left: 10%;
}
}
&#13;
<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">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#collapse-menu"> <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>
<div class="collapse navbar-collapse" id="collapse-menu">
<ul class="nav navbar-nav middle-left">
<li><a href="#">Link</a>
</li>
</ul>
<ul class="nav navbar-nav middle-right">
<li><a href="#">Link</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a class="nav-link-custom" href="#">Sign In</a>
</li>
</ul>
</div>
</div>
</nav>
&#13;
答案 1 :(得分:0)
将margin
CSS包含在媒体查询中,以便仅在扩展版本中影响文本。
@media (min-width: 768px) {
.middle-left {
margin-left: 25%;
}
.middle-right {
margin-left: 10%;
}
}