html - div 标签在 'position: fixed;' 之后顶部有 16px 的边距

标签 html css css-position margin fixed

我的网站顶部有一个标题部分,当人们向下滚动页面时,我希望它保持固定。页眉的背景是纯白色背景上的黑色。

添加 position:fixed; 规则后,它似乎在页面顶部之间添加了大约 16px 的边距。

#container-id-01 {
    height: 100px;
    width: 100%;
    background-color: #000;
    margin-top: 0;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 0;
    position: fixed;
}

我已经尝试将 margin 更改为 float:left; 但它仍然没有任何区别。 width: 100%; 需要一个百分比来填充页面的整个宽度。

有什么方法可以去掉边距吗?

最佳答案

添加 !important 无效,正文已设置为 padding:0;

我听取了一位评论者的建议,top:0; 成功了

:)

关于html - div 标签在 'position: fixed;' 之后顶部有 16px 的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31122142/

相关文章:

php - 单击 php 中的链接(来自数据库)后没有任何显示

javascript - 浏览器问题 :Branching Select Drop Down Not Supporting in IE 7 or 8

CSS 文件中的 PHP header

css - 水平居中绝对定位元素低于另一个元素的中心

html - 连字符或下划线最好写HTML类或ID名称

javascript - iframe 隐藏时停止

html - 在 CSS 中保留列

html - 创建一个图层开/关的页面

html - 一个页面中的两个 CSS 绝对定位项

css - 具有绝对定位的复杂布局