Html 如何使导航栏始终位于顶部?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13371186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make the nav bar always at the top?
提问by Shamoon
I'm using Foundationby ZURBand trying to get the nav bar to the top.
我正在使用FoundationbyZURB并试图将导航栏置于顶部。
回答by Alex Wayne
I have no idea what those 2 things are, but this is how you fix something in place regardless of window scroll position with CSS:
我不知道这 2 件事是什么,但这就是你如何用 CSS 修复窗口滚动位置的方法:
#navbar {
position: fixed;
top: 0px;
width: 100%;
}?
See here: http://jsfiddle.net/qC2Dt/
回答by vinknee
If you're using foundations, you can use:
如果您使用基础,则可以使用:
<nav class="top-bar fixed"></nav>
回答by Timar Ivo Batis
Adding to Alex Wayne's answer:
添加到亚历克斯韦恩的答案:
I found it necessary to add a z-indexwith a high enough number for the navbar to appear always on top of other elements.
我发现有必要添加一个足够大的z-index,以便导航栏始终出现在其他元素的顶部。
#navbar {
z-index: 10000;
position: fixed;
top: 0px;
width: 100%;
}?
回答by Matt Clark
use the style:
使用样式:
position:fixed;
top:0px;
回答by Grez.Kev
You can also use the class designed by bootstrap.
您也可以使用由 bootstrap 设计的类。
<nav class="navbar-fixed-top">

