删除图像下方的空白

发布于 2024-12-09 17:02:36 字数 197 浏览 8 评论 0原文

在 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?

Screenshot displaying white space below image

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

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

发布评论

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

评论(9

梦纸 2024-12-16 17:02:36

您会看到下降部分的空间(悬挂在“y”和“p”底部的位),因为默认情况下 img 是内联元素。这消除了间隙:

.youtube-thumb img { display: block; }

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:

.youtube-thumb img { display: block; }
淡莣 2024-12-16 17:02:36

如果您不想修改块模式,可以使用下面的代码:

img{vertical-align:text-bottom}

或者您可以按照斯图尔特的建议使用以下代码:

img{vertical-align:bottom}

You can use code below if you don't want to modify block mode:

img{vertical-align:text-bottom}

Or you can use following as Stuart suggests:

img{vertical-align:bottom}
年少掌心 2024-12-16 17:02:36

如果您想将图像保留为内联,可以在其上放置 vertical-align: topvertical-align: Bottom 。默认情况下,它在基线上对齐,因此其下方有几个像素。

If you would like to preserve the image as inline you can put vertical-align: top or vertical-align: bottom on it. By default it is aligned on the baseline hence the few pixels beneath it.

℡Ms空城旧梦 2024-12-16 17:02:36

我设置了 JSFiddle 来测试此问题的几种不同解决方案。基于[模糊]标准

1) 最大的灵活性

2)没有奇怪的行为

这里接受的答案

img { display: block; }

是很多人推荐的(例如在 这篇优秀的文章),实际上排名第四。

第一名、第二名和第三名都是这三个解决方案之间的折腾:

1) @Dave Kok 和 @Hasan Gursoy 给出的解决方案:

img { vertical-align: top; } /* or bottom */

优点:

  • 全部显示值适用于父级和 img。
  • 没有非常奇怪的行为; img 的任何兄弟姐妹都会落在您期望的位置。
  • 非常高效。

缺点:

  • 在父级和img都具有“display: inline”的[完全有效]情况下,该属性的值可以确定img父级的位置(有点奇怪)。

2) 在父元素上设置 font-size: 0;

.parent {
    font-size: 0;
    vertical-align: top;
}
.parent > * {
    font-size: 16px;
    vertical-align: top;
}

因为这个 [kind of] 需要在父元素上设置 vertical-align: top img,这基本上是第一个解决方案的扩展。

优点:

  • 所有显示值都适用于父级和 img。
  • 没有非常奇怪的行为; img 的任何兄弟姐妹都会落在您期望的位置。
  • 修复了 img 任何同级图像的内联空白问题
  • 尽管在父级和 img 都具有“display: inline”的情况下,这仍然会移动父级的位置,但至少您再也看不到父级了。

缺点:

  • 代码效率较低。
  • 这假设“正确”标记;如果 img 有文本节点同级,它们将不会显示。

3)在父元素上设置line-height: 0

.parent {
    line-height: 0;
    vertical-align: top;
}
.parent > * {
    line-height: 1.15;
    vertical-align: top;
}

与第二个解决方案类似,为了使其完全灵活,它基本上成为第一个解决方案的扩展。

优点:

  • 在所有显示组合上的行为类似于前两个解决方案,除非父级和 img 具有“display: inline”。

缺点:

  • 代码效率较低。
  • 在父级和 img 都有“display: inline”的情况下,我们会变得很疯狂。 (也许使用“line-height”属性不是最好的主意......)

所以你已经知道了。我希望这能帮助一些可怜的灵魂。

I've set up a JSFiddle to test several different solutions to this problem. Based on the [vague] criteria of

1) Maximum flexibility

2) No weird behavior

The accepted answer here of

img { display: block; }

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:

img { vertical-align: top; } /* or bottom */

pros:

  • All display values work on both the parent and img.
  • No very strange behavior; any siblings of the img fall where you'd expect them to.
  • Very efficient.

cons:

  • In the [perfectly valid] case of both the parent and img having `display: inline`, the value of this property can determine the position of the img's parent (a bit strange).

2) Setting font-size: 0; on the parent element:

.parent {
    font-size: 0;
    vertical-align: top;
}
.parent > * {
    font-size: 16px;
    vertical-align: top;
}

Since this one [kind of] requires vertical-align: top on the img, this is basically an extension of the 1st solution.

pros:

  • All display values work on both the parent and img.
  • No very strange behavior; any siblings of the img fall where you'd expect them to.
  • Fixes the inline whitespace problem for any siblings of the img.
  • Although this still moves the position of the parent in the case of the parent and img both having `display: inline`, at least you can't see the parent anymore.

cons:

  • Less efficient code.
  • This assumes "correct" markup; if the img has text node siblings, they won't show up.

3) Setting line-height: 0 on the parent element:

.parent {
    line-height: 0;
    vertical-align: top;
}
.parent > * {
    line-height: 1.15;
    vertical-align: top;
}

Similar to the 2nd solution in that, to make it fully flexible, it basically becomes an extension of the 1st.

pros:

  • Behaves like the first two solutions on all display combinations except when the parent and img have `display: inline`.

cons:

  • Less efficient code.
  • In the case of both the parent and img having `display: inline`, we get all sorts of crazy. (Maybe playing with the `line-height` property isn't the best idea...)

So there you have it. I hope this helps some poor soul.

递刀给你 2024-12-16 17:02:36

我发现了这个问题,这里的解决方案都不适合我。我找到了另一个解决方案,可以消除 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.

羁绊已千年 2024-12-16 17:02:36

有这个问题,在其他地方找到了完美的解决方案,如果你不想使用块,只需添加

img { vertical-align: top }

Had this prob, found perfect solution elsewhere if you dont want you use block just add

img { vertical-align: top }
似梦非梦 2024-12-16 17:02:36
.youtube-thumb img {display:block;} or .youtube-thumb img {float:left;}
.youtube-thumb img {display:block;} or .youtube-thumb img {float:left;}
叹沉浮 2024-12-16 17:02:36

将 div .youtube-thumb 的高度指定为图像的高度。这应该会在 Firefox 浏览器中解决问题。

.youtube-thumb{ height: 106px }

Give the height of the div .youtube-thumb the height of the image. That should set the problem in Firefox browser.

.youtube-thumb{ height: 106px }
旧情别恋 2024-12-16 17:02:36

如前所述,图像被视为文本,因此底部是为了容纳那些讨厌的内容:“p,q,y,g,j”;最简单的解决方案是分配 img display:block;在你的CSS中。

但这确实抑制了与文本一起流动的标准图像行为。保持这种行为并消除空间。我建议用这样的东西包裹图像。

<style>
    .imageHolder
    {
        display: inline-block;
    }
    img.noSpace
    {
        display: block;
    }
</style>
<div class="imageHolder"><img src="myimg.png" class="noSpace"/></div>

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.

<style>
    .imageHolder
    {
        display: inline-block;
    }
    img.noSpace
    {
        display: block;
    }
</style>
<div class="imageHolder"><img src="myimg.png" class="noSpace"/></div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文