我想在 CSS 中显示图像:before
元素。
.withimage:before {
content: url(path/to/image.svg);
display: block;
height: 20px;
width: 20px;
}
问题是,height
and width
应用于元素,但 SVG 不会缩小。如何将尺寸应用于之前创建的实际元素?
示例:https://plnkr.co/edit/UgryaObojs6PCU579oGY https://plnkr.co/edit/UgryaObojs6PCU579oGY
您可以使用 svg 作为背景图像:
.withimage:before {
content: "";
display:block;
height:125px;
width:125px;
background-size: 125px 125px;
background-image: url(test.svg);
background-repeat: no-repeat;
}
Here is example https://plnkr.co/edit/RCuUeONrKoVo4qOvBDk1?p=preview
您也可以尝试使用这个:
.withimage:before {
content: url("data:image/svg+xml; utf8, <svg.. code here</svg>");
display:block;
height:20px;
width:20px;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)