晚上好的社区,我很长一段时间"潜伏者",我想非常感谢大家所有的信息和辛勤工作。我发现自己面临着一些挑战/问题。
我尝试设置主导航(navbar-default),以便在桌面和移动版本上都能正常运行。
我想设置一个右侧菜单链接,该链接可用作下拉菜单,但它可以在网站的桌面版和移动版上使用。
以下是我想到的一些图片:
桌面视图最右边有徽标,旁边有链接,最右边的链接(Link#3)有下拉菜单(见下文):
平板电脑/移动宽度使徽标保持在左侧,隐藏链接#1和#2,并且仍然可以通过最右侧的菜单切换保持Link#3下拉菜单(见下文):
当菜单打开(点击汉堡包)时,菜单显示正常并显示链接#1,#2。
答案 0 :(得分:0)
你想做点什么like this?
HTML
<nav class="navbar navbar-default">
<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">
<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 navbar-left" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div><!-- /.navbar-collapse -->
<ul class="nav navbar-nav navbar-right mobileNav pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.container-fluid -->
</nav>
CSS
.mobileNav {
position: absolute;
right: 20px;
top: 0px;
}
@media only screen
and (min-device-width : 414px)
and (max-device-width : 736px) {
.mobileNav {
position: absolute;
right: 90px;
top: -2px;
}
}
@media only screen
and (min-device-width : 320px)
and (max-device-width : 568px) {
.mobileNav {
position: absolute;
right: 90px;
top: -2px;
}
}
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (-webkit-min-device-pixel-ratio: 1) {
.mobileNav {
position: absolute;
right: 90px;
top: -2px;
}
}
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (-webkit-min-device-pixel-ratio: 2) {
.mobileNav {
position: absolute;
right: 90px;
top: -2px;
}
}
更新代码:
链接更新:http://codepen.io/MaGiO/pen/eNYaep
HTML:
<nav class="navbar navbar-default">
<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">
<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 navbar-left" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<!-- /.navbar-collapse -->
<ul class="nav navbar-nav navbar-right mobileNav pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
</div>
<!-- /.container-fluid -->
</nav>
CSS:
.mobileNav {
position: absolute;
right: 20px;
top: 0px;
}
@media only screen and (max-width: 768px) {
.mobileNav {
position: absolute;
right: 80px !important;
top: 0px;
width: 195px;
text-align: right;
}
.navbar-nav .open .dropdown-menu {
text-align: right;
border: 1px solid #efefef;
margin-top: 2px;
}
.navbar-default .navbar-nav>.open>a,
.navbar-default .navbar-nav>.open>a:hover,
.navbar-default .navbar-nav>.open>a:active,
.navbar-default .navbar-nav>.open>a:focus {
background:none;
}
}