CSS 将 Div 标签放在页面顶部,没有空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19333190/
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
CSS Put Div Tag at top of page without space
提问by Ramy Nabiel
I want to put a div tag with id "wrapper" at top of page, but the problem is
that there is a white space between the div tag "wrapper is yellow color"
and the top of page.
我想在页面顶部放置一个 id 为“wrapper”的 div 标签,但问题是在 div 标签“wrapper is yellow color”
和页面顶部之间有一个空白区域。
My question is how can I remove the white space between the div tag and the top of page?
我的问题是如何删除 div 标签和页面顶部之间的空白?
Here is my code
这是我的代码
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body {
margin: 0;
padding:0;
}
#wrapper {
width:1000px;
text-align:center;
margin-right:auto;
margin-left:auto;
margin-top:0px;
background-color: yellow;
padding:0px;
}
</style>
</head>
<body>
<div id="wrapper">
Testing
</div>
</body>
</html>
回答by AME
Try this in the css code:
在 css 代码中试试这个:
{
position:absolute;
top:0px;
}
You can use the right
or left
to make a space between the div and the corner
您可以使用right
或left
在 div 和角落之间留出空间
回答by André Augusto Costa Santos
The problem is: https://stackoverflow.com/a/5910170/2670516
问题是:https: //stackoverflow.com/a/5910170/2670516
Try replace all your code by:
尝试通过以下方式替换所有代码:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
body {
margin: 0;
padding:0;
}
#wrapper {
width:1000px;
text-align:center;
margin-right:auto;
margin-left:auto;
margin-top:0px;
background-color: yellow;
padding:0px;
}
</style>
</head>
<body>
<div id="wrapper">
Testing
</div>
</body>
</html>
回答by Niks
try this ..
尝试这个 ..
{
position:absolute;
top:0;
left:0;
right:0;
margin:0 auto;
width:1000px;
}
hope this works
希望这有效