Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradients hidden using SVG symbols

Tags:

css

gradient

svg

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 two circles, but the red one is hidden:

<svg xmlns="http://www.w3.org/2000/svg" style='display:none' >
  <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>
like image 678
DanielBlazquez Avatar asked Nov 12 '16 12:11

DanielBlazquez


1 Answers

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>
like image 141
Paul LeBeau Avatar answered Oct 03 '22 03:10

Paul LeBeau