SVG透明背景网站

Gil*_*mbo 32 svg background web

我试图将此SVG代码的背景更改为透明而没有成功.我是SVG的新手,不知怎的,我无法在谷歌找到解决方案; 任何人都可以帮忙吗?

演示:http://jsfiddle.net/kougiland/SzfSJ/1/

<svg xmlns="http://www.w3.org/2000/svg" width="300px" height="100px" viewBox="0 0 300 100">
    <rect x="0" y="0" width="300" height="100" stroke="transparent" stroke-width="1" />
    <circle cx="0" cy="50" r="15" fill="blue" stroke="transparent" stroke-width="1">
       <animateMotion 
       path="M 0 0 H 300 Z" 
       dur="3s" 
       repeatCount="indefinite" 
       />
    </circle>

    <circle id="rotatingBall" cx="0" cy="50" r="15" fill="green" stroke="transparent" stroke-width="1" opacity="0.8"></circle>
    <animateTransform
        xlink:href="#rotatingBall"
        attributeName="transform"
        begin="0s"
        dur="2s"
        type="rotate"
        from="0 20 20"
        to="360 100 60"
        repeatCount="indefinite" 
        />
</svg>
Run Code Online (Sandbox Code Playgroud)

Rob*_*son 40

透明不是SVG规范的一部分,尽管许多UAs(如Firefox)确实支持它.SVG方式是设置strokenone,或者设置stroke-opacity0.

您也不要在<rect>元素上设置任何填充值,默认为黑色.对于要添加的透明矩形fill="none".

  • @mindplay.dk [没有一个是有效的关键字](https://www.w3.org/TR/SVG11/single-page.html#painting-SpecifyingPaint)。我没有对它进行基准测试,**我实现了它**。你看过我的[个人资料](/sf/users/72661081/?tab=profile)吗? (19认同)
  • 这个答案已经过时了。当前版本的 SVG 规范已[采用](https://www.w3.org/TR/css3-values/#colors)[CSS3 规范](https://www.w3.org/TR/css3-values/#colors)中的“transparent”关键字。 org/TR/css-color-3/#transparent)。 (2认同)

Fer*_*ras 9

在矩形内,您可以使用 fill-opacity="0.5"

<rect x="0" y="0" width="300" height="100" stroke="transparent" stroke-width="1" fill="green" fill-opacity="0.5" />
Run Code Online (Sandbox Code Playgroud)