gpt4 book ai didi

html - 带有/非固定标题的固定侧导航栏在滚动后在顶部留下间隙

转载 作者:行者123 更新时间:2023-11-28 04:34:57 26 4
gpt4 key购买 nike

我正在处理的页面有标题、侧导航控件(固定),当然还有内容。

我遇到的问题是,如果内容足够长以致于让用户滚动,则固定侧导航栏保持固定但会在其上方留下标题大小的间隙。

这看起来应该是一个简单的修复,我可能只是忽略了一些东西。如果可能的话,我更愿意使用纯 css 或没有 jQuery 的纯 js。

fiddle example ,可能必须扩大“结果”区域才能看到侧边导航。

<body>
<nav> ... </nav>
<div class="wrapper">
<div class="sidebar-wrapper">...</div>
<div class="page-content-wrapper">...</div>
</div>
</body>

CSS

#sidebar-wrapper {
z-index: 1000;
position: fixed;
left: 250px;
width: 0;
height: 100%;
margin-left: -250px;
overflow-y: auto;
background: #f5f5f5;
border-right: 1px solid #ccc;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
#page-content-wrapper {
width: 100%;
position: absolute;
padding: 15px;
}

最佳答案

不能只用 CSS 来完成。这是 Javascript(使用 jQuery):

$(window).scroll(function() {
var scrollTop = $(window).scrollTop();
if (scrollTop <= 70)
$('.sidebar-wrapper').css('top', 70 - scrollTop);
else
$('.sidebar-wrapper').css('top', 0);
});

关于html - 带有/非固定标题的固定侧导航栏在滚动后在顶部留下间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41537850/

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