删除图像下方的空白
在 Firefox 中,只有我的视频缩略图在图像底部与其边框之间显示神秘的 2-3 个像素的空白(见下文)。
我已经在 Firebug 中尝试了所有我能想到的方法,但没有成功。
有什么想法如何删除这个空白吗?
In Firefox only my video thumbnails are displaying mysterious 2-3 pixels of white space between the bottom of my image and its border (see below).
I've tried everything I can think of in Firebug with no luck.
Any ideas how can I remove this white space?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您会看到下降部分的空间(悬挂在“y”和“p”底部的位),因为默认情况下
img
是内联元素。这消除了间隙:You're seeing the space for descenders (the bits that hang off the bottom of 'y' and 'p') because
img
is an inline element by default. This removes the gap:如果您不想修改块模式,可以使用下面的代码:
或者您可以按照斯图尔特的建议使用以下代码:
You can use code below if you don't want to modify block mode:
Or you can use following as Stuart suggests:
如果您想将图像保留为内联,可以在其上放置
vertical-align: top
或vertical-align: Bottom
。默认情况下,它在基线上对齐,因此其下方有几个像素。If you would like to preserve the image as inline you can put
vertical-align: top
orvertical-align: bottom
on it. By default it is aligned on the baseline hence the few pixels beneath it.我设置了 JSFiddle 来测试此问题的几种不同解决方案。基于[模糊]标准
这里接受的答案
是很多人推荐的(例如在 这篇优秀的文章),实际上排名第四。
第一名、第二名和第三名都是这三个解决方案之间的折腾:
1) @Dave Kok 和 @Hasan Gursoy 给出的解决方案:
优点:
缺点:
2) 在父元素上设置
font-size: 0;
:因为这个 [kind of] 需要在父元素上设置
vertical-align: top
img
,这基本上是第一个解决方案的扩展。优点:
缺点:
3)在父元素上设置
line-height: 0
:与第二个解决方案类似,为了使其完全灵活,它基本上成为第一个解决方案的扩展。
优点:
缺点:
所以你已经知道了。我希望这能帮助一些可怜的灵魂。
I've set up a JSFiddle to test several different solutions to this problem. Based on the [vague] criteria of
The accepted answer here of
which is recommended by a lot of people (such as in this excellent article), actually ranks fourth.
1st, 2nd, and 3rd place are all a toss-up between these three solutions:
1) The solution given by @Dave Kok and @Hasan Gursoy:
pros:
cons:
2) Setting
font-size: 0;
on the parent element:Since this one [kind of] requires
vertical-align: top
on theimg
, this is basically an extension of the 1st solution.pros:
cons:
3) Setting
line-height: 0
on the parent element:Similar to the 2nd solution in that, to make it fully flexible, it basically becomes an extension of the 1st.
pros:
cons:
So there you have it. I hope this helps some poor soul.
我发现了这个问题,这里的解决方案都不适合我。我找到了另一个解决方案,可以消除 Chrome 中图像下方的空白。我必须将
line-height:0;
添加到 CSS 中的 img 选择器中,图像下方的间隙就消失了。疯狂的是这个问题在 2013 年的浏览器中仍然存在。
I found this question and none of the solutions here worked for me. I found another solution that got rid of the gaps below images in Chrome. I had to add
line-height:0;
to the img selector in my CSS and the gaps below images went away.Crazy that this problem persists in browsers in 2013.
有这个问题,在其他地方找到了完美的解决方案,如果你不想使用块,只需添加
Had this prob, found perfect solution elsewhere if you dont want you use block just add
将 div
.youtube-thumb
的高度指定为图像的高度。这应该会在 Firefox 浏览器中解决问题。Give the height of the div
.youtube-thumb
the height of the image. That should set the problem in Firefox browser.如前所述,图像被视为文本,因此底部是为了容纳那些讨厌的内容:“p,q,y,g,j”;最简单的解决方案是分配 img display:block;在你的CSS中。
但这确实抑制了与文本一起流动的标准图像行为。保持这种行为并消除空间。我建议用这样的东西包裹图像。
As stated before, the image is treated as text, so the bottom is to accommodate for those pesky: "p,q,y,g,j"; the easiest solution is to assign the img display:block; in your css.
But this does inhibit the standard image behavior of flowing with the text. To keep that behavior and eliminate the space. I recommend wrapping the image with something like this.