额外的白色空间页面顶部

时间:2012-12-15 04:04:04

标签: css whitespace margin removing-whitespace

我为我的网站创建了一个包装器div来包含正文的全部内容,但由于某种原因,我在包装器div上方有额外的空白区域。我无法确切地指出为什么会这样;我为body和wrapper div设置了零填充和零边距:

<body onload="init()" style="margin:0px; padding:0px;">
<div id="wrapper" style="background-color:#000000; margin:0px; padding:0px;">
<div id="pagecontent">
<nav id="navlogo" style="margin:10px;">Some Navigation Stuff
</nav></div></div></body>

(页面内容Div包含所有网页的元素并以其为中心。) 我也有这个页面内容的CSS:

#pagecontent
{
margin: 0px auto;
width: 1044px;
box-shadow:inset 0px 0px 15px black;
background-color:#000000;
}

我尝试在包装器div上使用-10px的负边距,这样就可以了;那是摆脱这个白色空间的唯一方法吗?

1 个答案:

答案 0 :(得分:2)

<nav id="navlogo" style="margin:10px;">

此保证金包括保证金最高限额:10px - 这就是问题所在。 margin:10px; = margin-top:10px;margin-right:10px;margin-bottom:10px;margin-left:10px;

要解决这个问题,您可以将其更改为:

margin:10px;margin-top:0;

或要让导航栏转到顶部,只需将margin:10px;更改为padding:10px;

相关问题