简体   繁体   English

修复div导航从滚动时隐藏的问题

[英]Fixing div navigation from hiding upon scroll

I have this sample HTML5 page which have a navigation and a content area pasted on JSFiddle . 我有这个示例HTML5页面,该页面具有导航和粘贴在JSFiddle上的内容区域。

The problem is that <div id="nav"> isn't fixed when I scroll vertically. 问题是,垂直滚动时<div id="nav">并没有固定。 How can I make the navigation to be fixed on the top of the browser even with scrolled vertically? 即使垂直滚动,如何将导航固定在浏览器顶部?

DEMO DEMO

body {
    margin: 0px;
    width: 100%;
    height: 120%;
    background: red;
}
#nav {
    position: fixed;
    width: 100%;
    z-index: 99;
    height: 25px;
    background: blue;
}

Use position:fixed and z-index property (the issue you had was due to the layers : your fixed div was under #area div) : 使用position:fixedz-index属性(您的问题归因于图层: fixed div位于#area div下):

#nav{
   position:fixed;
   top:0;
   width:100%;
   height: 25px;
   z-index:50;
   background: blue;
}

Example

Create another hidden navigation (same with already used nav), and show it when user scrolls down enough. 创建另一个隐藏的导航(与已经使用的导航相同),并在用户向下滚动足够时显示它。

Here is a good tutorial to do that. 这是一个很好的教程

And here is some edited and working example from my website. 这是我网站上一些经过编辑且有效的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM