[英]Remove space between header and the page
My header has a space above it. 我的标题上方有一个空格。 I want it to stay to the top without any space.
我希望它保持顶部,没有任何空间。 I attached an image that shows the space.
我附加了一张显示空间的图像。
Here is my code: 这是我的代码:
body { background-color: red; } #example { height: 75px; background-color: #484848; }
<header id="example"> example </header>
The <body>
element has a default margin. <body>
元素具有默认边距。 Remove it: 去掉它:
body { background-color: red; } #example { height: 75px; background-color: #484848; } body { margin-top: 0; }
<header id="example"> example </header>
Many elements come with default margins and/or padding. 许多元素带有默认边距和/或填充。
This is due to the browser's default style sheet . 这是由于浏览器的默认样式表 。
Add this to your elements where necessary: 必要时将其添加到您的元素中:
margin: 0;
padding: 0;
Here is a sample default stylesheet browsers might use: https://www.w3.org/TR/CSS22/sample.html 这是浏览器可能使用的示例默认样式表: https : //www.w3.org/TR/CSS22/sample.html
EDIT (since you added more code) 编辑 (因为您添加了更多代码)
In your case, you need to remove the margins from the body
element. 在这种情况下,您需要从
body
元素中删除边距。
body { margin: 0; }
If this is your complete HTML and CSS, the red margin can't be that wide, but anyway: Add 如果这是您完整的HTML和CSS,则红色边距不能那么宽,但是无论如何:添加
html, body {
margin: 0;
}
to your CSS 到你的CSS
There are two things you could do. 您可以做两件事。 One is remove
height: 75px
so the div takes only it's natural height (the height of the text). 一种是删除
height: 75px
因此div仅采用其自然高度(文本的高度)。
Or you could add vertical-align: top
to the #example
to move the text to the top - div stays the same size here. 或者,您可以将#
vertical-align: top
添加到#example
以将文本移到顶部-div在此处保持相同大小。
This solves your problem. 这样可以解决您的问题。 element body have a margin by default.
元素主体默认情况下具有边距。
body{
margin: 0;
}
in the top of the css document. 在css文档顶部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.