Icon into SVG Circle

2019-08-07 08:35发布

How do I out an icon (e.g. font-awesome) into an SVG element?

I want that this is centered in the circle.

<svg class="svg" width=100 height=100>
    <circle cx=50 cy=50 r=25>
    </circle>    
    <i class="icon-check"></i>
</svg>

Here is a test: http://jsfiddle.net/L2Lm3fgm/

标签: html css3 svg
1条回答
再贱就再见
2楼-- · 2019-08-07 08:52

Just find out the code for the character font-awesome is using in its class, and use that character as a text node. Remember to group the circle and the text node together.

Example:

svg { 
    margin: 24px auto;
    display: block;
}
circle {
    fill: transparent;
    stroke: #f00;
    stroke-width: 2;
}
svg text#chk {
    font-family: sans-serif;
    font-size: 24px; 
    fill: #00f;
}
<svg class="svg" width=100 height=100>
    <g>
        <circle cx=50 cy=50 r=25></circle>    
        <text id="chk" x=42 y=58>&#x2713;</text>
    </g>
</svg>

Example Fiddle: http://jsfiddle.net/abhitalks/L2Lm3fgm/2/

查看更多
登录 后发表回答