div 之间的额外空间从何而来?

发布于 2024-12-19 19:39:12 字数 222 浏览 1 评论 0原文

http://www.lethalmonk6.byethost24.com/index.html

如果您检查firebug “项目链接”div 之间的间距,每个 div 之间添加了几个像素的边距。我将边距设置为 20 px,然后添加这些小位。它从哪里来?

http://www.lethalmonk6.byethost24.com/index.html

If you inspect with firebug the spacing between the "project-link" divs, there are a few pixels of added margin between each div. I have the margin set to 20 px, and then these little bits gets added on. Where is it coming from?

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

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

发布评论

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

评论(5

余生共白头 2024-12-26 19:39:12

您正在使用 display:inline-block 因此元素之间的空白就是您所看到的。您可以删除 div 之间的空白或使用 float: left 代替。

详细说明...如果您使用 display: inline-block 执行以下操作:

<div></div><div></div>

而不是这样做:

<div></div>
<div></div> // White space is added because of the new line

You're using display:inline-block so the white space between the elements is what you are seeing there. You can either remove the white space between the divs or use float: left instead.

To elaborate... if you're using display: inline-block do this:

<div></div><div></div>

Instead of this:

<div></div>
<div></div> // White space is added because of the new line
破晓 2024-12-26 19:39:12

正如 Terminal Frost 所说,将 float: left 添加到类中,并删除 display: inline-block。此外,将 content: "." 添加到父 div 容器中,以解决这样做时遇到的换行问题。

As Terminal Frost said, add float: left to the class, and remove display: inline-block. Additionally, add content: "." to the parent div container to fix the wrapping issue you'll have from doing that.

思念绕指尖 2024-12-26 19:39:12

正如 Lucifer Sam 所说,display:inline-block 将向您显示元素之间的空间(如果有)。

给出的解决方案很好:

<div></div><div></div>

但是对于内容较大的元素,我个人更喜欢这种在 display:inline-block 元素之间没有空格的解决方案。这就是我所做的:

   <div>
       large content
   </div><!-- No space
--><div>
       large content 2
   </div>

As Lucifer Sam said, display:inline-block will show you space between element if there are one.

The slution given is good:

<div></div><div></div>

But for element with large content, i personnaly prefer this solution of not having the white space between display:inline-block elements. This is what i do:

   <div>
       large content
   </div><!-- No space
--><div>
       large content 2
   </div>
困倦 2024-12-26 19:39:12

我对这里提供的解决方案不太满意,然后我遇到了一个修复程序,我之前实际上用它来解决这个问题,但忘记了它......

您可能需要的只是简单地添加 font-size : 0; 到父容器(您可以为子容器覆盖此规则,因此它不会破坏您的字体)。

所以,这是一个基本的例子:

<div class="font-zero">
    <div class="inline-block"></div>
    <div class="inline-block"></div>
    <div class="inline-block"></div>
</div>

<style>
    .font-zero { font-size: 0; }
    .inline-block { display: inline-block; }
</style>

有了这个例子,你不必担心代码中的标记(就我个人而言,我认为删除代码中的换行符来解决这个问题真的很难看),而且你也不需要使用浮动,由于多种原因这可能不是最佳的。

由于此页面是第一个 Google 结果,我希望下次遇到此问题时能到达这里并忘记简单的修复...也许它对其他人也有用:)

I wasn't quite happy with the provided solutions here and then I came across a fix that I actually was using to address this issue before, but forgot about it...

All you might need is to simply add font-size: 0; to the parent container (you can overwrite this rule for the children, so it shouldn't break your fonts).

So, here's a basic example:

<div class="font-zero">
    <div class="inline-block"></div>
    <div class="inline-block"></div>
    <div class="inline-block"></div>
</div>

<style>
    .font-zero { font-size: 0; }
    .inline-block { display: inline-block; }
</style>

With that example you don't have to worry about the markup in your code (personally, I think removing line breaks in the code to solve this issue is really ugly) and also you don't need to use floating, which might be not optimal for many reasons.

Since this page was the first Google result, I hope I'll get here next time I come across this issue and forget the easy fix... And maybe it would be useful for someone else too :)

贪了杯 2024-12-26 19:39:12

我只是偶然发现了这里,我的解决方案是在我使用 filter:blur(5px); 的元素之一上设置 overflow:hidden;

I just stumbled here and my solution was to set overflow: hidden; on one of the elements that in my case was using filter: blur(5px);.

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