简体   繁体   English

额外填充下 <img> 标签?

[英]Extra padding under an <img> tag?

I'm getting some sort of padding below an img tag in my webpage. 我在网页上的img标签下面有一些填充。 The html looks like: html看起来像:

<li>
  <div>Title</div>
  <img src='...' width='60px' height='60px' />
</li>

Yeah so there is about 5 pixels of padding beneath the image (I can tell because the bg color of the parent li item is different). 是的,因此在图像下面有大约5个像素的填充(我可以说,因为父项目的bg颜色不同)。 I tried assigning a class to the img tag with padding/margin/border all set to zero, but no change. 我尝试将一个类分配给img标签,其中padding / margin / border都设置为零,但没有变化。 I'm wondering if there's anything I'm missing about img tags that could be causing this padding to appear? 我想知道是否有任何关于img标签的遗漏可能导致这种填充出现?

When I remove the img tag, and just leave the 'title' div, the extra padding is gone, 当我删除img标签,然后离开'title'div时,额外的填充消失了,

Thanks 谢谢

------------- Update ------------------- -------------更新-------------------

This is only happening on FF, chrome and safari look ok. 这只发生在FF,铬和野生动物园看起来不错。 Firebug also shows the padding is part of the img element. Firebug还显示填充是img元素的一部分。

If you can set the image's display style to block that should solve the problem. 如果您可以将图像的display样式设置为block解决问题的方式。 Setting vertical-align to bottom or middle should also work. vertical-align设置为bottommiddle也应该有效。 I think the problem comes about because Firefox tries to position inline images so their bottom edge is aligned with the baseline of the text, and so there is space below the image for the text descenders. 我认为问题出现是因为Firefox试图定位内嵌图像,因此它们的下边缘与文本的基线对齐,因此图像下方有文本下限的空间。

只需在样式标记中将高度属性添加到图像中,就像需要细线一样,然后需要在外部为safari指定1px。

I think you might be seeing the space after your image before the end of the list item. 我想你可能会在列表项结束之前看到图像后面的空格。 Try getting rid of the whitespace in your html, like this: 尝试摆脱html中的空白,如下所示:

<li><div>Title</div><img src='...' width='60px' height='60px' /></li>

What if you force the padding margin and border to 0 on img elements? 如果你在img元素上强制填充边距和边框为0怎么办? Are you working with Firebug? 你在使用Firebug吗?

You could provide a link or more code to allow a better resolution of your problem, but: 您可以提供一个或多个代码以便更好地解决问题,但是:

1. Verify if your image is 60px by 60px as setup in your img tag 1.验证您的图像是否为imp标记中的60px x 60px设置

2. Remove padding and margin and border from your img, you may have a default setting for img tag that causes what you're refereeing 2.从你的img中删除填充和边距以及边框,你可能有一个img标签的默认设置会导致你的裁判

3. The extra space under your img may come from other elements in your page, meaning that with the img in place, some element forces that extra space 3.你的img下面的额外空间可能来自你页面中的其他元素,这意味着在img到位的情况下,一些元素会强加额外的空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM