此页面显示两个图像,每个图像都包含在一个单独的跨度内显示为内嵌块。对第一个图像应用“display:block”的附加样式,该图像将删除图像与其绿色边界跨度底部之间的空间(当元素样式为内联时,为下行提供空间)。反之,该空间在第二个图像(仍显示为内联)和第二个跨度的蓝色边框之间可见。什么解释了行内块的这种行为?
为什么将第一张图像显示为块会在第一幅图像的跨度和包含跨度的元素(橙色框)之间创建空间?是因为当一个内联元素被包含在另一个内部时,分配给下行的空间以垂直边界的方式合并?另外我想知道为什么在蓝色顶部和橙色容器之间有一个像素的空间。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>test</title>
<style>
.product_box {
border: 1px solid green;
display:inline-block; /* to put products side by side */
}
.product_image {
display:block;
}
.shop_box { /* contains shop logo, shop URL, link to view additional items (when not all items are displayed), and all the shop's products */
text-align:center;
border:1px solid orange;
}
#stats {
border:1px solid blue;
display: inline-block;
}
</style>
</head>
<body>
<div class="shop_box">
<span class="product_box">
<img class="product_image" src="http://i.imgur.com/o2udo.jpg">
</span>
<span id="stats">
<img src="http://i.imgur.com/o2udo.jpg" alt="test">
</span>
</div>
</body></html>
我不知道原因,但我知道,加入' line-height:0'将删除白色缝隙。谢谢你的小提琴,但'看''你在说什么对我来说真的很难。您可能想要使用较小的图像,以便差距更明显.http:// jsfiddle。net/A6aLW/1/ – mrtsherman 2011-12-20 17:16:57