Change SVG fill color in :before or :after CSS

后端 未结 2 1624
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 06:35

I have a SVG graphic put like this:

a::before { content: url(filename.svg); }

When I hover over the tag, I really want the SVG to change t

2条回答
  •  醉酒成梦
    2020-12-08 07:09

    Using the content property generates (non-exposed) markup functionally equvialent to an svg in an element.

    You cannot apply style to elements inside the svg document because:

    1. styles are not allowed to cascade across documents
    2. when using (or content, or any css image property that references svg) the svg document is not exposed by the browsers due to security concerns

    Similar questions, but for background-image here and here.

    So, to do what you want you must get around the two points above somehow. There are various options for doing that, e.g using inline svg, using filters (applied to the ) or generating different svg files (or data URIs), as in your question.

提交回复
热议问题