Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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 设置img标记的src属性的等效项_Html_Css - Fatal编程技术网

Html 设置img标记的src属性的等效项

Html 设置img标记的src属性的等效项,html,css,Html,Css,我是这样做的: <img class="myimg" /> .myimg{ content:url('/images/user_logo.png') center no-repeat; } myimg先生{ 内容:url('/images/user_logo.png')中心不重复; } 但是图像没有显示出来。我想在不使用背景图像的情况下实现它请使用背景图像: .myimg{ background-image: url('/images/user_logo.png');

我是这样做的:

<img class="myimg" />
.myimg{
    content:url('/images/user_logo.png') center no-repeat;
}

myimg先生{
内容:url('/images/user_logo.png')中心不重复;
}

但是图像没有显示出来。我想在不使用背景图像的情况下实现它

请使用
背景图像

.myimg{
 background-image: url('/images/user_logo.png');
}

尝试使用
:before
:after
方法来实现此目的。下面是堆栈示例


您的表现几乎不错,只保留url(但并非所有浏览器都支持此功能)

.myimg{
内容:url('https://lorempixel.com/400/200/');
}

我希望它不使用背景图像确保您针对的是正确的类,因此
.myimg
而不是
.mgimg
。另外,是否有这样添加图像的原因?为什么不
(更新以获得正确的路径),然后使用CSS将其样式设置为您想要的中心位置?
.myimg:before {
    content:url('../images/user_logo.png');
}