SVG图像不透明度渐变

时间:2016-06-25 23:45:57

标签: css firefox svg gradient fade

我在.svg文件中使用这段代码在元素上应用不透明淡出渐变。以下代码效果很好,但从左到右淡化,而不是从上到下垂直。

我需要做些什么代码才能实现这一目标?谢谢你的帮助!

SVG文件:

<?xml version="1.0" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
      "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <svg xmlns="http://www.w3.org/2000/svg"
         version="1.1"
         baseProfile="full">
         <mask id="m1" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox">
            <linearGradient id="g" gradientUnits="objectBoundingBox" x2="1">
              <stop stop-color="white" offset="0"/>
              <stop stop-color="white" stop-opacity="0" offset="1"/>
            </linearGradient>
            <rect x="0" y="0" width="1" height="1" fill="url(#g)"/>
          </mask>
    </svg>

CSS:

mask: url(/mypath/mask.svg#m1);

1 个答案:

答案 0 :(得分:3)

您可以使用x1y1x2y2属性设置渐变的方向。

对于从顶部开始向下的垂直渐变,您需要从(0,0)到(0,1)。

<linearGradient id="g" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="0" y2="1">
    <stop stop-color="white" offset="0"/>
    <stop stop-color="white" stop-opacity="0" offset="1"/>
</linearGradient>
相关问题