html - 如何使固定导航与窗口顶部齐平

标签 html css

我在页面顶部的固定导航栏上遇到了一些问题。它应该与页面顶部齐平,但不是。这是我的 HTML:

<nav>
<a href="#">
<div id="logo">
lorem
</div></a>
</nav>

<ul>
*enough li's to go past the bottom of the screen*
</ul>

和我的 CSS:

body {
    margin: 0px;
    padding: 0px;
}

nav {
    position: fixed;
    display: block;
    color: white;
    margin: 0 auto;
    padding: 0;
    width: 100%;
    height: 60px;
    background-color: #4d4d4d;
}

#logo {
    padding-left: 1%;
    padding-right: 1%;
    color: #75cc83;
    width: 180px;
    height: 100%;
    background-color: #333333;
    font-size: 3em;
    font-family: candara, sans-serif;

}

一旦我将内容放入其中(在本例中为列表项),固定导航似乎只有问题

最佳答案

top:0 添加到您的导航规则中:

nav {
    position: fixed;
    display: block;
    color: white;
    margin: 0 auto;
    padding: 0;
    width: 100%;
    height: 60px;
    background-color: #4d4d4d;
    top:0;
}

jsFiddle example

关于html - 如何使固定导航与窗口顶部齐平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19412708/

相关文章:

javascript - 预加载 html 网页或非 flash web 应用程序?

html - 以固定高度垂直对齐 div 中的内联 block

javascript - 验证码成功后如何重定向

css - 在 WordPress 中找不到 CSS 菜单

html - 对齐按钮 html 电子邮件

html - 我如何在 Bootstrap 中垂直和水平居中 asp 按钮

javascript - Chrome Web Extension,使用按钮在新选项卡中打开网页

Javascript/CSS : Using buttons to vertically scroll page

html - 如何制作出圆形的按钮效果

html - 如何设置与另一半不同的 <hr> 样式?