[英]Replace svg element with icon
I am trying to make my SVG circle elements look like shopping carts. 我试图使我的SVG圈子元素看起来像购物车。 Is there a way to completely replace the definition of a circle element in svg so that it renders a certain icon ?
有没有一种方法可以完全替换svg中的circle元素的定义,以使其呈现特定图标?
<circle cx="280px" cy="411px" r="4.976112128"></circle>
<i class="fa fa-shopping-cart"></i>
If not, is there a simpler way to display an icon whenever the circle element is called ? 如果不是,是否有更简单的方法在每次调用circle元素时显示图标? Thank you very much !
非常感谢你 !
You can try styling the <circle>
element with CSS's background-image
property: 您可以尝试使用CSS的
background-image
属性设置<circle>
元素的样式:
circle {
background-image: url(http://www.example.com/bck.png);
}
You can define your own elements and call those instead of circles. 您可以定义自己的元素,然后调用这些元素而不是圆形。 This way you can still use circles if needed elsewhere.
这样,您仍然可以根据需要在其他地方使用圈子。
If you are not looking to use CSS you can use "defs" and "use". 如果您不想使用CSS,则可以使用“ defs”和“ use”。
<?xml version="1.0" encoding="utf-8"?>
<!-- from this website http://tutorials.jenkov.com/svg/svg-and-css.html -->
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<defs>
<g id="shopcart">
<image x="499.5" y="242.4" height="40" width="40" id="cart" preserveAspectRatio="none" xlink:href="c:\temp\cart.png" opacity="1" style="pointer-events: none"/>
</g>
</defs>
<use xlink:href="#shopcart" x="10" y="50" transform="translate(150,50)" />
<use xlink:href="#shopcart" x="100" y="250" />
<use xlink:href="#shopcart" x="200" y="250" />
<use xlink:href="#shopcart" x="300" y="250" />
</svg>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.