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');
}