gpt4 book ai didi

html - 使用 .affix 时元素宽度错误

转载 作者:行者123 更新时间:2023-11-28 03:13:44 26 4
gpt4 key购买 nike

在此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>

最佳答案

解决它的一种方法是添加 left: 15px; right: 15px; 以匹配父 col 的 padding,这是在元素未附加时控制宽度的内容。

<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>

关于html - 使用 .affix 时元素宽度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45579484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com