How to apply a style to an embedded SVG?

前端 未结 3 862
终归单人心
终归单人心 2020-11-22 12:13

When an SVG is directly included in a document using the tag, you can apply CSS styles to the SVG via the document\'s stylesheet. However, I am tryi

3条回答
  •  臣服心动
    2020-11-22 12:47

    If the only reason for using the tag to inlcude the SVG is that you do not want to clutter your source code with the markup from the SVG, you should take a look at SVG injectors like SVGInject.

    SVG injection uses Javascript to inject an SVG file inline into your HTML document. This allows for clean HTML source code while making the SVGs fully styleable with CSS. A basic example looks like this:

    
    
      
    
    
      
    
    
    

提交回复
热议问题