Bootstrap 折叠的导航栏 - 我希望菜单左对齐但它右对齐
Bootstrap collapsed navbar - I want menu to be aligned to left but it is aligned to right
我制作了简单的 bootstrap 导航栏,当显示 window 很小时它会折叠。我还在那个导航栏中添加了图像。
现在当我缩小浏览器 window 并出现汉堡菜单时,我的可折叠菜单没有对齐到网页的最左侧,请看下面的附图。
我想让那个可折叠菜单向左对齐,我该怎么做?
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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 href="index.html" class="navbar-left logo">
<img src="img/logo.png" height="40px">
</a>
<a class="navbar-brand text-hide" href="index.html">title</a>
</div>
<div class="collapse navbar-collapse navbar-left" id="menu">
<ul class="nav navbar-nav">
<li class="active">
<a href="index.html">Bio</a>
</li>
<li>
<a href="portfolio.html">Portfolio</a>
</li>
<li>
<a href="#">Freebies</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
提前致谢
Screenshot of my collapsed navabar issue
进行以下更改
1)在图像后移动按钮标签
2)在img和button标签中添加如下样式属性
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a href="index.html" class="navbar-left logo">
<img src="img/logo.png" height="40px" style="float:left;">
</a>
<button type="button" style="float:left;" class="navbar-toggle" data-toggle="collapse" data-target="#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 text-hide" href="index.html">title</a>
</div>
<div class="collapse navbar-collapse navbar-left" id="menu">
<ul class="nav navbar-nav">
<li class="active">
<a href="index.html">Bio</a>
</li>
<li>
<a href="portfolio.html">Portfolio</a>
</li>
<li>
<a href="#">Freebies</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
对您的 CSS 使用媒体查询,这样它就不会改变移动视图。
工作示例:
@media (min-width: 768px) {
.nav {
margin-left: 212px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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 href="#" class="navbar-left logo">
<img src="http://placehold.it/50x50/f00/fff" height="50px">
</a>
<a class="navbar-brand text-hide" href="#">title</a>
</div>
<div class="collapse navbar-collapse" id="menu">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Bio</a>
</li>
<li><a href="#">Portfolio</a>
</li>
<li><a href="#">Freebies</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
我制作了简单的 bootstrap 导航栏,当显示 window 很小时它会折叠。我还在那个导航栏中添加了图像。
现在当我缩小浏览器 window 并出现汉堡菜单时,我的可折叠菜单没有对齐到网页的最左侧,请看下面的附图。
我想让那个可折叠菜单向左对齐,我该怎么做?
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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 href="index.html" class="navbar-left logo">
<img src="img/logo.png" height="40px">
</a>
<a class="navbar-brand text-hide" href="index.html">title</a>
</div>
<div class="collapse navbar-collapse navbar-left" id="menu">
<ul class="nav navbar-nav">
<li class="active">
<a href="index.html">Bio</a>
</li>
<li>
<a href="portfolio.html">Portfolio</a>
</li>
<li>
<a href="#">Freebies</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
提前致谢
Screenshot of my collapsed navabar issue
进行以下更改 1)在图像后移动按钮标签 2)在img和button标签中添加如下样式属性
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a href="index.html" class="navbar-left logo">
<img src="img/logo.png" height="40px" style="float:left;">
</a>
<button type="button" style="float:left;" class="navbar-toggle" data-toggle="collapse" data-target="#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 text-hide" href="index.html">title</a>
</div>
<div class="collapse navbar-collapse navbar-left" id="menu">
<ul class="nav navbar-nav">
<li class="active">
<a href="index.html">Bio</a>
</li>
<li>
<a href="portfolio.html">Portfolio</a>
</li>
<li>
<a href="#">Freebies</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
对您的 CSS 使用媒体查询,这样它就不会改变移动视图。
工作示例:
@media (min-width: 768px) {
.nav {
margin-left: 212px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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 href="#" class="navbar-left logo">
<img src="http://placehold.it/50x50/f00/fff" height="50px">
</a>
<a class="navbar-brand text-hide" href="#">title</a>
</div>
<div class="collapse navbar-collapse" id="menu">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Bio</a>
</li>
<li><a href="#">Portfolio</a>
</li>
<li><a href="#">Freebies</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>