【发布时间】:2020-12-06 07:45:27
【问题描述】:
我正在开发一个页面,其中既有sidebar 也有navbar 我必须将导航栏固定到顶部,以便获得更好的用户体验。
问题
但是当我使用内置的fixed-top 引导类时,它会覆盖侧边栏,我的navbar 在侧边栏的宽度之后开始,
所以我只想把它固定在顶部,这样滚动变得更容易
我的导航栏代码
<div>
<Navbar collapseOnSelect expand="lg" className="py-3 navbar_style">
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
<Navbar.Collapse id="responsive-navbar-nav">
<Nav className="mr-auto"></Nav>
<Nav>
<Nav.Link href="#deets">Logout</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
</div>
侧边栏 CSS
.sidebar {
height: 100%;
width: 100px;
position: fixed;
top: 0;
left: 0;
transition: all 0.6s;
background: #ffffff 0% 0% no-repeat padding-box;
box-shadow: 0px 3px 6px #00000029;
opacity: 1;
}
我已经在沙箱中编写了最少的代码,我只想将导航栏固定到顶部而不覆盖我的侧边栏,请检查代码沙箱
【问题讨论】:
-
所以您想将导航栏固定在屏幕顶部,但在侧边栏下方?我是否正确理解您的问题?为什么不能只做 position: fixed, zIndex: 0?
-
这能回答你的问题吗? z-index not working with fixed positioning
标签: html css reactjs bootstrap-4