Gradients hidden using SVG symbols

后端 未结 1 332
一生所求
一生所求 2021-01-12 16:15

I am using SVG symbols this way, but the display:none of the SVG is hidden the gradients of the graphic. Any idea?

In the example below, there should be

相关标签:
1条回答
  • 2021-01-12 16:43

    Instead of display: none, you can just use width="0" height="0".

    <svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" style="display:block">
      <defs>
        <style>.red-gradient{fill:url(#gradient)}</style>
        <linearGradient id="gradient" x1="0" x2="0" y1="0" y2="1">
           <stop offset="0%" stop-color="red"/>
           <stop offset="100%" stop-color="darkred"/>
        </linearGradient>
      </defs>
      <symbol id="mysymbol" viewBox="0 0 100 100">
        <circle class="red-gradient" cx="0" cy="50" r="50" />
        <circle fill="green" cx="100" cy="50" r="50" />
      </symbol>
     </svg>
    
    <svg><use xlink:href="#mysymbol" /></svg>

    0 讨论(0)
提交回复
热议问题