Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
548 views
in Technique[技术] by (71.8m points)

css - SVG with radialGradient not work in browsers

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:

expected view of svg

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...