如何使菜单栏在滚动时固定在顶部
我想制作一个菜单栏,滚动时固定在页面顶部。类似于 Facebook 的顶部菜单。
另外,我想要一个 div 将徽标浮动在菜单栏的左侧,并在菜单栏的右侧放置一个导航浮动。
I'd like to make a menubar, which is fixed on the top of the page while scrolling. Something like the top menu in Facebook.
Also, I want a div holding the logo float at the left of menubar, and a nav float at the right of the menubar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这应该可以帮助你开始
This should get you started
要将 div 设置在固定位置,您可以使用
to set a div at position fixed you can use
postition:absolute;
标记相对于其直接父元素定位元素。我注意到即使在示例中也没有滚动空间,当我尝试时,它不起作用。
因此,要实现 facebook 浮动菜单,应使用
position:fixed;
标签。它将元素替换/保留在给定/指定的位置,并且页面的其余部分可以平滑滚动 - 即使使用响应式页面。请参阅 CSS 位置属性文档 :)
The
postition:absolute;
tag positions the element relative to it's immediate parent.I noticed that even in the examples, there isn't room for scrolling, and when i tried it out, it didn't work.
Therefore, to pull off the facebook floating menu, the
position:fixed;
tag should be used instead. It displaces/keeps the element at the given/specified location, and the rest of the page can scroll smoothly - even with the responsive ones.Please see CSS postion attribute documentation when you can :)