Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You don’t even need the second <use>, you can just render the <circle> normally and use it in the clipPath:

   <svg width="200" height="200" viewBox="-100 -100 200 200">
     <defs>
       <clipPath id="ball">
  -      <circle cx="0" cy="20" r="70" />
  +      <use href="#round" />
       </clipPath>
     </defs>
  
  -  <circle cx="0" cy="20" r="70" fill="#D1495B" />
  +  <circle cx="0" cy="20" r="70" fill="#D1495B" id="round" />
(Personally I’d also drop the <defs>-wrapping. Never did understand why structuring them that way is recommended, I don’t think it actually gets you anything except for the vanishingly rare case where you want to put something that would render if it were not in a <defs> tag—I say “vanishingly rare” because situations like you showed—//defs/circle—should normally actually use <symbol>.)


I like to do the defs in one svg in one part of the html page, and use them elsewhere in other svgs. It's clean and readable that way. But to each their own I guess!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: