.nav>li>a:hover,
.nav>li>a:focus .navbar-header>a:hover,
.navbar-header>a:focus {
background-color: #7F613F;
}
.icon-color {
color: #282828;
}
.nav {
display: flex;
}
@media(max-width: 768px) {
.nav>li {
float: left
}
}

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="navbar navbar-fixed-top" style="background-color: #b39369; max-height: 50px;">
<div class="container-fluid">
<div class="navbar-header">
<button class="navbar-toggle navbar-right" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar" style="background-color:#282828"></span>
<span class="icon-bar" style="background-color:#282828"></span>
<span class="icon-bar" style="background-color:#282828"></span>
</button>
<ul class="nav navbar-nav">
<li><a href="#"><i class="glyphicon glyphicon-comment icon-color"></i></a></li>
<li><a href="#"><i class="glyphicon glyphicon-list-alt icon-color"></i></a></li>
<li><a href="#"><i class="glyphicon glyphicon-user icon-color"></i></a></li>
</ul>
</div>
<div class="collapse navbar-collapse">
<form class="navbar-form navbar-left">
<div class="input-group input-group-sm" style="max-width:360px;">
<input class="form-control" placeholder="Search" name="srch-term" id="srch-term" type="text">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="glyphicon glyphicon-cog icon-color"></i></a>
<ul class="dropdown-menu">
<li><a href="">More</a></li>
<li><a href="">More</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</body>
&#13;
正如您在代码段中看到的那样,我的代码在导航栏中有导航栏和图标。
但是当我使导航栏或浏览器变窄时,图标glyphicon-comment, glyphicon-list-alt, glyphicon-user
变得丑陋。
我希望这些图标保持不变,就好像浏览器足够宽。
这些图标离浏览器太远了。我不知道为什么会这样。
无论浏览器的广泛性如何,我如何让这些图标保持其位置。
只有搜索栏和其他内容可以折叠。 但其他事情应该保持同样的立场。
无论浏览器的广泛程度如何,如何使这些图标固定在其位置上?
答案 0 :(得分:1)
确保您已将内容包装在一行中,然后使用列来布置此行中的内容。
现在更新以下内容以包含这两者,现在抵消移动视口的负边距。
有关Bootstrap网格的更多内容:
https://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
.nav>li>a:hover, .nav>li>a:focus .navbar-header>a:hover, .navbar-header>a:focus {
background-color: #7F613F;
}
.icon-color {
color: #282828;
}
.nav {
display: flex;
}
@media (max-width: 768px) {
.nav > li {
float: left;
}
}
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="navbar navbar-fixed-top" style="background-color: #b39369; max-height: 50px;">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="navbar-header">
<button class="navbar-toggle navbar-right" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar" style="background-color:#282828"></span>
<span class="icon-bar" style="background-color:#282828"></span>
<span class="icon-bar" style="background-color:#282828"></span>
</button>
<ul class="nav navbar-nav">
<li><a href="#"><i class="glyphicon glyphicon-comment icon-color"></i></a></li>
<li><a href="#"><i class="glyphicon glyphicon-list-alt icon-color"></i></a></li>
<li><a href="#"><i class="glyphicon glyphicon-user icon-color"></i></a></li>
</ul>
</div>
<div class="collapse navbar-collapse">
<form class="navbar-form navbar-left">
<div class="input-group input-group-sm" style="max-width:360px;">
<input class="form-control" placeholder="Search" name="srch-term" id="srch-term" type="text">
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="glyphicon glyphicon-cog icon-color"></i></a>
<ul class="dropdown-menu">
<li><a href="">More</a></li>
<li><a href="">More</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</body>