5


我想在页面顶部放置一个 id 为“wrapper”的 div 标签,但问题是 div 标签“wrapper is yellow color”和页面顶部之间有一个空格。

我的问题是如何删除 div 标签和页面顶部之间的空白?

这是我的代码

    <!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>

4

3 回答 3

11

在 css 代码中试试这个:

{
 position:absolute;
 top:0px;
}

您可以使用rightorleft在 div 和角之间留出空间

于 2013-10-12T10:39:07.763 回答
2

问题是:https ://stackoverflow.com/a/5910170/2670516

尝试通过以下方式替换所有代码:

<!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>
于 2013-10-12T11:29:29.347 回答
-1

尝试这个 ..

{
    position:absolute;
    top:0;
    left:0;
    right:0;
    margin:0 auto;
    width:1000px;
}

希望这有效

于 2013-10-12T11:07:50.380 回答