SVG fill-opacity、stroke-opacity与opacity同时设置时的冲突

fill-opacity、stroke-opacity与opacity的作用

  • fill-opacity 用来设置填充颜色透明度(范围:0 - 1)
  • stroke-opacity 用来设置笔触(边框)颜色的透明度(范围:0 - 1)
  • opacity 用来设置元素整体(包括”填充”和”边框”)的透明值(范围: 0 到 1)
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400">
    <circle cx="80" cy="80" r="50" style="fill:pink;stroke:orange;stroke-width:5;"/>
    <circle cx="160" cy="80" r="50" style="fill:pink;stroke:orange;stroke-width:5;fill-opacity:0.1;" />
    <circle cx="240" cy="80" r="50" style="fill:pink;stroke:orange;stroke-width:5;stroke-opacity:0.1;" />
    <circle cx="320" cy="80" r="50" style="fill:pink;stroke:orange;stroke-width:5;opacity:0.1;" />
</svg>

这里写图片描述

当fill-opacity、stroke-opacity与opacity属性一起使用时,数值小的生效,结果与位置先后无关

<html>
    <body>
        <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
            <circle cx="80" cy="80" r="50" style="fill:blue;stroke:red;stroke-width:5;"/>
            <circle cx="160" cy="80" r="50" style="fill:blue;stroke:red;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.1;opacity:0.9" />
            <circle cx="240" cy="80" r="50" style="fill:blue;stroke:red;stroke-width:5;opacity:0.9;fill-opacity:0.1;stroke-opacity:0.1;" />
        </svg>
        <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
            <circle cx="80" cy="80" r="50" style="fill:yellow;stroke:green;stroke-width:5;"/>
            <circle cx="160" cy="80" r="50" style="fill:yellow;stroke:green;stroke-width:5;fill-opacity:1.0;stroke-opacity:1.0;opacity:0.1;" />
            <circle cx="240" cy="80" r="50" style="fill:yellow;stroke:green;stroke-width:5;opacity:0.1;fill-opacity:1.0;stroke-opacity:1.0;" />
        </svg>
    </body>
</html>

这里写图片描述

fill-opacity、stroke-opacity与opacity的最大值为1,最小值为0,超过该范围则认为该形状无效,不显示

<html>
    <body>
        <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
            <circle cx="80" cy="80" r="50" style="fill:blue;stroke:red;stroke-width:5;"/>
            <circle cx="160" cy="80" r="50" style="fill:blue;stroke:red;stroke-width:5;fill-opacity:1;stroke-opacity:-5;opacity:-5;" />
            <circle cx="240" cy="80" r="50" style="fill:blue;stroke:red;stroke-width:5;fill-opacity:-5;stroke-opacity:1;opacity:-5;" />
            <circle cx="240" cy="80" r="50" style="fill:blue;stroke:red;stroke-width:5;fill-opacity:-5;stroke-opacity:-5;opacity:1;" />
        </svg>
        <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
            <circle cx="80" cy="80" r="50" style="fill:yellow;stroke:green;stroke-width:5;"/>
            <circle cx="160" cy="80" r="50" style="fill:yellow;stroke:green;stroke-width:5;fill-opacity:-5;stroke-opacity:-5;opacity:5;" />
            <circle cx="240" cy="80" r="50" style="fill:yellow;stroke:green;stroke-width:5;fill-opacity:5;stroke-opacity:5;opacity:-5;" />
        </svg>
    </body>
</html>

这里写图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值