简体   繁体   English

一个不需要的空格 <img> 和相邻的 <div>

[英]Unwanted whitespace between an <img> and an adjacent <div>

I'm having a little bit weird problem with my HTML. 我的HTML有点奇怪的问题。 I never had this problem before. 我之前从未遇到过这个问题。

test page: http://jsfiddle.net/egjJ5/1/ 测试页面: http//jsfiddle.net/egjJ5/1/

I see white space between the image and the black div. 我看到图像和黑色div之间的空白区域。 When I take out DTD, it renders fine. 当我拿出DTD时,它会很好。

Do i have a problem with my html or css? 我的html或css有问题吗?

The image is an inline-block and the div underneath it is a block . 图像是一个inline-block ,它下面的div是一个block There are several ways you could fix this. 有几种方法可以解决这个问题。 One would be to add display: block to the image as in this example . 一种方法是将display: block添加到图像中,如本例所示

只需将img元素设为块元素:

display: block;

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

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