Image 以img为背景的跨度

Image 以img为背景的跨度,image,html,Image,Html,只是好奇,为什么我不能在这个跨度上看到我的背景图像,除非我使用位置:绝对?!是因为span是一个内联元素吗 .thumb { background: url("images/yts.png") no-repeat; height: 150px; width: 200px; } <span class="thumb"></span> .thumb{ 背景:url(“images/yts.png”)不重复; 高度:150像素; 宽度:200px;

只是好奇,为什么我不能在这个跨度上看到我的背景图像,除非我使用位置:绝对?!是因为span是一个内联元素吗

.thumb {
    background: url("images/yts.png") no-repeat;
    height: 150px;
    width: 200px;
}

<span class="thumb"></span>
.thumb{
背景:url(“images/yts.png”)不重复;
高度:150像素;
宽度:200px;
}

是。问题是,对于内联元素,width属性没有效果。因此,没有内容的跨度的宽度为0,然后只有零像素的背景可见
您可以使用display:inline块来解决这个问题,而无需绝对定位它