SVG with radialGradient not work in browsers

无人久伴 提交于 2020-05-31 01:53:54

问题


Problem:

The following svg code not work in browsers:

<svg width="207" height="209" viewBox="0 0 207 209" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path fill-rule="evenodd" clip-rule="evenodd" d="M96.2318 8.29356C149.379 4.30837 195.684 44.2918 199.657 97.599C203.631 150.906 163.767 197.351 110.62 201.336C57.473 205.321 11.1677 165.338 7.19452 112.031C3.2213 58.7234 43.0847 12.2787 96.2318 8.29356Z" stroke="url(#paint0_angular)" stroke-width="2"/>
    <defs>
        <radialGradient id="paint0_angular" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(103.426 104.815) rotate(-94.2626) scale(96.7891 96.5016)">
            <stop stop-color="#FF7870"/>
            <stop offset="1" stop-color="#FF7870" stop-opacity="0"/>
        </radialGradient>
    </defs> 
</svg>

If replace stroke atribute in path fragment of svg with simple color (for example #f00) - it works, but with radial gradient - not works.


Question:

  1. Is there a way to make this svg valid for browsers?

OR

  1. Is there a way to make this element with HTML & CSS?

All information, that I've found not solves the problems, because:

  • Background of circle must be transparent
  • Gradient has grades around the circle (not from top to bottom)

P. S. Expected view of svg:


回答1:


Shortly you can do this using only CSS with mask and conic-gradient but the support is still low for both.

The below example works only on chrome:

.box {
  width:200px;
  height:200px;
  margin:20px auto;
  border-radius:50%;
  background:conic-gradient(transparent,red);
  -webkit-mask:radial-gradient(farthest-side,transparent calc(100% - 10px),#fff calc(100% - 9px));
          mask:radial-gradient(farthest-side,transparent calc(100% - 10px),#fff calc(100% - 9px));
}

body  {
  background:url(https://picsum.photos/id/100/1000/1000) center/cover;
}
<div class="box">

</div>



来源:https://stackoverflow.com/questions/59100540/svg-with-radialgradient-not-work-in-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!