这个问题已经问过,但我的问题有点不同。
Bootstrap menu (nav) collapse horizontally instead of vertical
Change bootstrap navbar collapse breakpoint without using LESS
当我调整大小时,导航栏会崩溃。但是当我点击按钮图标时,我仍然有一个水平菜单。 这是图片:
这是我的代码。
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div>
<div>
<div class="jumbotron" style="padding: 0px">
<div class="card fancy-card">
<div class="card">
<div class="container">
<nav class="navbar navbar-default" style="background-color: lightskyblue">
<div class="container-fluid">
<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 sr-only" href="#">Menu</a>
</div>
<!--class="collapse navbar-collapse" to hide some elts of menu-->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a routerLink="/home/accueil" routerLinkActive="active">home</a>
</li>
<li>
<a href="javascript:void(0)"
class="dropdown-toggle"
data-toggle="dropdown">Item1<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/home/item11" routerLinkActive="active">Item11</a>
</li>
<li><a routerLink="/home/item12"
routerLinkActive="active">Item12</a></li>
</ul>
</li>
<li>
<a href="javascript:void(0)"
class="dropdown-toggle"
data-toggle="dropdown">Item2<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/home/item21" routerLinkActive="active">Item21</a>
</li>
<li><a routerLink="/home/item21" routerLinkActive="active">Item22</a>
</li>
</ul>
</li>
<li>
<a href="javascript:void(0)"
class="dropdown-toggle"
data-toggle="dropdown">Item3<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/home/item31" routerLinkActive="active">Item31</a>
</li>
<li><a routerLink="/home/item32" routerLinkActive="active">Item32</a>
</li>
</ul>
</li>
<li>
<a routerLink="/home/account" routerLinkActive="active">Account</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><input value="Déconnexion" (click)="logout()" type="submit"/></li>
</ul>
</div>
</div>
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
答案 0 :(得分:0)
这不是Bootstrap那样做的。你有一些其他的CSS让菜单水平。
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="card">
<div class="container">
<nav class="navbar navbar-default" style="background-color: lightskyblue">
<div class="container-fluid">
<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 sr-only" href="#">Menu</a>
</div>
<!--class="collapse navbar-collapse" to hide some elts of menu-->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a routerLink="/home/" routerLinkActive="active">home</a>
</li>
<li>
<a href="javascript:void(0)"
class="dropdown-toggle"
data-toggle="dropdown">Item1<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/home/item11" routerLinkActive="active">Item11</a>
</li>
<li><a routerLink="/home/item12"
routerLinkActive="active">Item12</a></li>
</ul>
</li>
<li>
<a href="javascript:void(0)"
class="dropdown-toggle"
data-toggle="dropdown">Item2<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/home/item21" routerLinkActive="active">Item21</a>
</li>
<li><a routerLink="/home/item21" routerLinkActive="active">Item22</a>
</li>
</ul>
</li>
<li>
<a href="javascript:void(0)"
class="dropdown-toggle"
data-toggle="dropdown">Item3<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/home/item31" routerLinkActive="active">Item31</a>
</li>
<li><a routerLink="/home/item32" routerLinkActive="active">Item32</a>
</li>
</ul>
</li>
<li>
<a routerLink="/home/account" routerLinkActive="active">Account</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><input value="Déconnexion" (click)="logout()" type="submit"/></li>
</ul>
</div>
</div>
</nav>
</div>
</div>
&#13;
答案 1 :(得分:0)
试试这个:
<nav class="navbar navbar-default" style="background-color: lightskyblue">
<div class="container-fluid">
<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 sr-only" href="#">Menu</a>
</div>
<!--class="collapse navbar-collapse" to hide some elts of menu-->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a routerLink="/home/" routerLinkActive="active">home</a>
</li>
<li>
<a href="javascript:void(0)"
class="dropdown-toggle"
data-toggle="dropdown">Item1<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/home/item11" routerLinkActive="active">Item11</a>
</li>
<li><a routerLink="/home/item12"
routerLinkActive="active">Item12</a></li>
</ul>
</li>
<li>
<a href="javascript:void(0)"
class="dropdown-toggle"
data-toggle="dropdown">Item2<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/home/item21" routerLinkActive="active">Item21</a>
</li>
<li><a routerLink="/home/item21" routerLinkActive="active">Item22</a>
</li>
</ul>
</li>
<li>
<a href="javascript:void(0)"
class="dropdown-toggle"
data-toggle="dropdown">Item3<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/home/item31" routerLinkActive="active">Item31</a>
</li>
<li><a routerLink="/home/item32" routerLinkActive="active">Item32</a>
</li>
</ul>
</li>
<li>
<a routerLink="/home/account" routerLinkActive="active">Account</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><input value="Déconnexion" (click)="logout()" type="submit"/></li>
</ul>
</div>
</div>
</nav>