【问题标题】:SVG background not applied未应用 SVG 背景
【发布时间】:2014-02-26 08:54:29
【问题描述】:

我制作了一个简单的 SVG 图像,但没有应用背景,但它应该应用。

到目前为止,我得到了以下代码:

<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" id="content" width="100%" height="100%" viewbox="0 0 800 1000" preserveaspectratio="xMidYMid meet" version="1.1">
  <defs>
    <lineargradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">
      <stop offset="0%" stop-color="#ffffff" stop-opacity="0"/>
      <stop offset="100%" stop-color="orange" stop-opacity="0.8"/>
    </lineargradient>
    <lineargradient id="gradientLine" x1="0%" y1="0%" x2="0%" y2="100%">
      <stop offset="0%" stop-color="orange" stop-opacity="0"/>
      <stop offset="100%" stop-color="orange" stop-opacity="0.6"/>
    </lineargradient>
  </defs>
  <g id="vis" transform="translate(330,670)">
    <path fill="url(#gradient)" d="M-112.87131548350527,-640.1250394579351A650,650 0 0,1 222.31309316168483,-610.8002035108404L0,0Z"/>
    <circle r="35" stroke="orange" fill="orange" opacity="1"/>
    <circle r="3" stroke="black" fill="black" opacity="1"/>
    <line x1="0" x2="-85" y1="0" y2="0" fill="black" stroke="black"/>
  </g>
</svg>

path 是黑色的,但它应该是从白色到橙色的渐变。

显然,当我在 jsfiddle 中运行我的代码时,它显示了良好的结果。但是当我尝试在 img 标签中或直接在浏览器中显示 SVG 时,我得到了黑色背景。有什么想法吗?

我做错了什么还是这是一个常见问题?

感谢您的帮助。

【问题讨论】:

    标签: svg background gradient


    【解决方案1】:

    我认为问题出在这里:

    <lineargradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">
    

    固定:

    <linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">
    

    【讨论】:

    • 显然,当我在 jsfiddle 中运行我的代码时,它显示了良好的结果。但是当我尝试在 img 标签中或直接在浏览器中显示 SVG 时,我得到了黑色背景。有什么想法吗?
    • 我发现你的错误 - lineargradient 而不是 linearGradient
    猜你喜欢
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 2011-05-14
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多