在此example中,您可以看到,当我们向下滚动时,搜索字段显示较大的宽度。如果我删除标签(带有搜索标志图标)-一切正常。我在其他标签上也遇到了同样的问题,比如,还有其他元素类,比如.panel-group、.panel-heading和e.t.c。我怎么才能修复它?
HTML代码:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<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>
<style>
.affix {
top: 20px;
}
</style>
<body>
<div class="container-fluid" style="background-color:#2196F3;color:#fff;height:200px;">
<h1>Bootstrap Affix Example</h1>
</div>
<br>
<div class="container">
<div class="row">
<nav class="col-sm-3">
<div class="nav nav-pills nav-stacked" data-spy="affix" data-offset-top="205">
<div class="input-group">
<i class="input-group-addon glyphicon glyphicon-search"></i>
<input name="search" type="text" class="form-control" placeholder="search">
</div>
<li>TEST 1</li>
<li>TEST 2</li>
<li>TEST 3</li>
</div>
</nav>
<div class="col-sm-9">
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
</div>
</div>
</div>
</body>发布于 2017-08-09 07:34:16
解决这个问题的一种方法是添加left: 15px; right: 15px;来匹配父col的填充,这就是当元素没有被附加时控制宽度的东西。
<title>Bootstrap Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<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>
<style>
.affix {
top: 20px;
left: 15px;
right: 15px;
}
</style>
<body>
<div class="container-fluid" style="background-color:#2196F3;color:#fff;height:200px;">
<h1>Bootstrap Affix Example</h1>
<h3>Fixed (sticky) vertical sidenav on scroll</h3>
<p>Scroll this page to see how the left navigation menu behaves with data-spy="affix".</p>
<p><strong>The left menu sticks to the page when you have scrolled a specified amount of pixels.</strong></p>
</div>
<br>
<div class="container">
<div class="row">
<nav class="col-sm-3">
<div class="nav nav-pills nav-stacked" data-spy="affix" data-offset-top="205">
<div class="input-group">
<i class="input-group-addon glyphicon glyphicon-search"></i>
<input name="search" type="text" class="form-control" placeholder="search">
</div>
<li>TEST 1</li>
<li>TEST 2</li>
<li>TEST 3</li>
</div>
</nav>
<div class="col-sm-9">
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
<h1>Some text to enable scrolling</h1>
</div>
</div>
</div>
</body>
</html>
https://stackoverflow.com/questions/45579484
复制相似问题