Bootstrap Affix with Bootstrap col-xx-yy class



当向下滚动时,我试图使用Bootstrap词缀将导航器(水平)固定到顶部。导航器在向下滚动时被固定在顶部,但可滚动的内容在其上方滚动,而不是在其下方滚动。

更多背景。。。主体,即可滚动内容是一个具有引导面板和入口字段的表单,这些字段使用col-md-*类来格式化布局。这个类的使用似乎添加了"position:relative"属性,这似乎导致了重叠。

我的问题。。。。我是CSS新手,所以

  • 我不明白为什么position:相对内容与position:fixed(navigator)重叠
  • 我不明白为什么bootstrap添加位置:相对于这些组件,没有额外的顶部、左侧、底部或右侧属性。如果没有这些属性之一,这难道不与默认的"position:static"相同吗
  • 最后,我该如何解决这个问题。我正在寻找一个完美的标准非破解解决方案,不会破坏引导升级

编辑:在起草这篇文章时,我有了一个想法,在导航器中添加了一个正z索引,可滚动的内容现在滚动到导航器后面。这是正确的解决方案吗?不过,我仍在寻找其他问题的答案。谢谢

*编辑2:在这里找到了我所有词缀问题的答案。https://www.jero.co.nz/blog/bootstrap-affix-plugin/我还有一个问题没有在这里解决。。。如果偏移量为零,则单击并滚动即可固定和取消固定。将偏移设置为1。

现在我需要弄清楚如何将此标记为已解决。*

这是我用W3Schools词缀示例创建的小提琴。https://jsfiddle.net/fLx60zvh/2/

谢谢你的帮助。

<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<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>
/* Note: Try to remove the following lines to see the effect of CSS positioning */
.affix {
top: 0;
width: 100%;
}
.affix + .container-fluid {
padding-top: 70px;
}
</style>
</head>
<body>
<div class="container-fluid" style="background-color:#F44336;color:#fff;height:200px;">
<h1>Bootstrap Affix Example</h1>
<h3>Fixed (sticky) navbar on scroll</h3>
<p>Scroll this page to see how the navbar behaves with data-spy="affix".</p>
<p>The navbar is attached to the top of the page after you have scrolled a specified amount of pixels.</p>
</div>
<nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="197">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Basic Topnav</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</nav>
<div class="container-fluid" style="height:1000px">
<div class="col-md-6">
<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 class="col-md-6">
<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>
</body>
</html>

找到了解决问题的方法。

在这里找到了我所有词缀问题的答案。很棒的博客!https://www.jero.co.nz/blog/bootstrap-affix-plugin/我还有一个问题没有在这里解决。。。如果偏移量为零,则单击并滚动即可固定和取消固定。将偏移设置为1。

最新更新