Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html span won';在span标记中不显示任何文本_Html_Css - Fatal编程技术网

Html span won';在span标记中不显示任何文本

Html span won';在span标记中不显示任何文本,html,css,Html,Css,如果我删除内部文本xxx,下面的范围将不会显示背景图像 <span style='background-image:url("http://gifsoup.com/web/images/soc4.gif")' style="height: 30px;"> xxx </span> xxx 但是,在兼容模式下,它可以在没有xxx的情况下工作 如何使其在没有任何内部文本的情况下工作?您需要添加宽度,并且可能需要执行显示:内联块,否则宽度为0,因此不可见。因为跨度默认为

如果我删除内部文本xxx,下面的范围将不会显示背景图像

<span style='background-image:url("http://gifsoup.com/web/images/soc4.gif")'  style="height: 30px;">
 xxx
</span>

xxx
但是,在兼容模式下,它可以在没有xxx的情况下工作


如何使其在没有任何内部文本的情况下工作?

您需要添加宽度,并且可能需要执行
显示:内联块
,否则宽度为0,因此不可见。

因为跨度默认为没有宽度或高度的内联元素。将CSS更改为:

span {
    display:inline-block;
    width:30px;
    background-image:url("http://gifsoup.com/web/images/soc4.gif");
    height:30px;
}


通过将显示从内联块更改为内联块,可以设置跨距的宽度和高度。

跨距元素是内联元素,因此没有宽度或高度。您必须在元素css中指定它应显示为块或内联块,然后指定图像的宽度和高度

span{
    display: inline-block;
    background-image:url("http://gifsoup.com/web/images/soc4.gif");
    width:30px;
    height:30px;
    border-radius: 5px;
}

不要在html中混合引号样式,您可以在内联css中使用单引号('),并为样式值保留双引号(“)。实际上,不要完全使用内联样式。根据此元素周围的上下文,
div
可能更合适。