带有radialGradient的SVG在浏览器中不起作用 [英] SVG with radialGradient not work in browsers

查看:219
本文介绍了带有radialGradient的SVG在浏览器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

以下svg代码在浏览器中不起作用:

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>

如果用简单的颜色(例如#f00)替换svg的path片段中的stroke属性-可以,但是使用径向渐变-不起作用.

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

问题:

  1. 有没有办法使该svg对浏览器有效?

OR

  1. 有没有一种方法可以使用HTML& CSS?

我发现的所有信息都不能解决问题,因为:

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

  • 圆圈的背景必须透明
  • 渐变具有围绕圆圈的等级(不是从上到下)

P. S.预期的svg视图:

推荐答案

很快,您只能使用带有maskconic-gradient的CSS来做到这一点,但是对这两者的支持仍然很低.

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

以下示例仅适用于chrome:

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>

这篇关于带有radialGradient的SVG在浏览器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆