div 之间的额外空间从何而来?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您正在使用
display:inline-block
因此元素之间的空白就是您所看到的。您可以删除 div 之间的空白或使用float: left
代替。详细说明...如果您使用
display: inline-block
执行以下操作:而不是这样做:
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 usefloat: left
instead.To elaborate... if you're using
display: inline-block
do this:Instead of this:
正如 Terminal Frost 所说,将
float: left
添加到类中,并删除display: inline-block
。此外,将content: "."
添加到父 div 容器中,以解决这样做时遇到的换行问题。As Terminal Frost said, add
float: left
to the class, and removedisplay: inline-block
. Additionally, addcontent: "."
to the parent div container to fix the wrapping issue you'll have from doing that.正如 Lucifer Sam 所说,
display:inline-block
将向您显示元素之间的空间(如果有)。给出的解决方案很好:
但是对于内容较大的元素,我个人更喜欢这种在
display:inline-block
元素之间没有空格的解决方案。这就是我所做的:As Lucifer Sam said,
display:inline-block
will show you space between element if there are one.The slution given is good:
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:我对这里提供的解决方案不太满意,然后我遇到了一个修复程序,我之前实际上用它来解决这个问题,但忘记了它......
您可能需要的只是简单地添加
font-size : 0;
到父容器(您可以为子容器覆盖此规则,因此它不会破坏您的字体)。所以,这是一个基本的例子:
有了这个例子,你不必担心代码中的标记(就我个人而言,我认为删除代码中的换行符来解决这个问题真的很难看),而且你也不需要使用浮动,由于多种原因这可能不是最佳的。
由于此页面是第一个 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:
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 :)
我只是偶然发现了这里,我的解决方案是在我使用
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 usingfilter: blur(5px);
.