为什么我的网页顶部有一个空白?

发布于 2024-11-17 03:28:34 字数 155 浏览 6 评论 0原文

我确信答案是显而易见的,但我还没有太多地使用 html/css...

浏览器顶部和第一个 div 之间有一个空白。我实在不明白为什么会有这样的差距。我在css中没有使用margin-top或padding-top或border-top,那为什么会有间隙呢?

谢谢!

I'm sure the answer is obvious, but I haven't been working with html/css that much...

There is a gap of white space in between the top of the browser and the first div. I don't really get why the gap is there. I didn't use margin-top or padding-top or border-top in the css, so why is there a gap?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

不必你懂 2024-11-24 03:28:34

虽然如果您实际发布一些代码或网站链接将会非常有帮助,但我认为这只是默认填充。大多数浏览器都有默认样式,例如您可能想要清除的 body 等内容。尝试这样的操作:

html, body{
   padding: 0;
   margin: 0;
}

如果这不能解决问题,您将需要提供更多信息。

While it would be extremely helpful if you actually posted some code or a link to the site, I would assume it's just the default padding. Most browsers have default styles for things like body that you may want to clear. Try something like this:

html, body{
   padding: 0;
   margin: 0;
}

If that doesn't fix it you'll need to give more information.

明媚如初 2024-11-24 03:28:34

如果没有看到任何内容,我想您要么需要清除 body 元素上的默认填充,要么在该 div 中有一个标题标签,这会增加一些额外的好处。

你使用重置吗? http://meyerweb.com/eric/tools/css/reset/

Without seeing anything I'd imagine you either need to clear the default padding on the body element or you have a heading tag in that div that is adding some extra goodness.

Are you using a reset? http://meyerweb.com/eric/tools/css/reset/

半边脸i 2024-11-24 03:28:34

如果页面用包装器包装,请使用:

 #wrap{
     margin:0 auto;
     padding:0
 }

if the page is wrapped with a wrapper, use:

 #wrap{
     margin:0 auto;
     padding:0
 }
帅气称霸 2024-11-24 03:28:34

再说一次,有一些背景会很好,但如果这些解决方案不能解决问题,那么就有一个很好的改变,你将成为利润崩溃的受害者。尝试将body的overflow属性设置为auto

Once again, some context would be nice but if these solutions aren't cutting it, then there's a good change your a victim of collapsing margins. Try setting the overflow property of the body to auto

秋日私语 2024-11-24 03:28:34

我也有同样的问题。浮动上部 div 解决了这个问题。

I had the same problem. Floating the upper divs solved it.

总以为 2024-11-24 03:28:34

我也有同样的问题。当我向 div 容器添加 30px 的填充时,它被修复了。我使用了

   .top-container {
       padding-top: 30px;
    }

我的问题发生在我将一些图像设置为我的 div 中的绝对位置(具有相对位置)之后。出于某种原因,出现了间隙,但设置填充对我有用。

I had the same problem. It was fixed when I added 30px of padding to my div container. I used

   .top-container {
       padding-top: 30px;
    }

My problem happened after I set some images to an absolute position in my div (which had a position of relative.) For some reason that gap appeared, but setting the padding worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文