gpt4 book ai didi

html - 无法让侧边菜单 scrollspy 粘在顶部

转载 作者:太空宇宙 更新时间:2023-11-04 12:52:22 25 4
gpt4 key购买 nike

我刚开始使用 bootstrap 3,但遇到了一个问题。我想要一个像 this 中那样的侧边菜单在向下滚动期间定位固定的文档并相应地突出显示部分。我设法完成了与此非常相似的事情,但是当我将窗口调整为移动尺寸时,侧面菜单与内容重叠,而不是在内容之上。如果您选中链接,当您调整窗口大小时,侧边菜单会位于内容之上。

我相信这里的罪魁祸首是 affix-top 但我把它留给 stackoverflow 中有经验的人

<body data-spy="scroll" data-target="#myScrollspy">
<!-- Page Content -->
<div class="container">

<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Title
<small>Subheading</small>
</h1>
</div>
</div>

<!-- Content Row -->
<div class="row">
<!-- Sidebar Menu -->
<div class="col-md-2" id="myScrollspy">
<ul class="nav nav-tabs nav-stacked affix-top" data-spy="affix" >
<li class="active"><a href="#section-1">Section One</a></li>
<li><a href="#section-2">Section Two</a></li>
<li><a href="#section-3">Section Three</a></li>
<li><a href="#section-4">Section Four</a></li>
<li><a href="#section-5">Section Five</a></li>
</ul>
</div>

<!-- Content Column -->
<div class="col-md-9">
<h2 id="section-1">Section One</h2>
<h2 id="section-2">Section Two</h2>
<h2 id="section-3">Section Three</h2>
<h2 id="section-4">Section Four</h2>
<h2 id="section-5">Section Five</h2>
</div>
</div>
</div>
</body>

如何解决这个问题?

最佳答案

您正在寻找的是 CSS 媒体查询,它允许您根据颜色、高度和宽度等媒体特性修改样式规则。您链接到的 Bootstrap 页面使用最小和最大宽度功能来更改侧边栏的显示方式,您可以在其 CSS file 中看到。靠近页面底部。相关代码如下所示:

@media (min-width: 768px) {
/* Adjust sidenav width */
.bs-docs-sidenav {
width: 166px;
margin-top: 20px;
}
.bs-docs-sidenav.affix {
top: 0;
}
}
@media (max-width: 767px) {
/* Sidenav */
.bs-docs-sidenav {
width: auto;
margin-bottom: 20px;
}
.bs-docs-sidenav.affix {
position: static;
width: auto;
top: 0;
}
}

我对其进行了一些简化,但这应该足以让您入门。当 max-width 小于 768px 时,侧边栏宽度将变为自动,词缀代码将保持侧边栏在页面顶部。

关于html - 无法让侧边菜单 scrollspy 粘在顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26070858/

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