具有图像模式的SVG仅在Chrome中有效

时间:2019-02-04 21:47:34

标签: html css svg

我正在尝试获取顶部倾斜的图像,并且该图像需要通过CMS更新。我发现最符合跨浏览器的方式是使用SVG,创建路径并为其提供模式。我现在拥有的代码是:

<svg class="workIntroImage" width="696px" height="921px" viewBox="0 0 696 921">
  <defs>
    <pattern id="workIntroImg" width="1920" x="0" y="0" height="1080" patternUnits="userSpaceOnUse">
      <image xlink:href="https://www.usmagazine.com/wp-content/uploads/2017/12/147234372_the-office-zoom.jpg" x="0" y="0" width="1920" height"1080"></image>
    </pattern>
  </defs>
  <g x="0" y="0" transform="translate(-37.000000, 0.000000)">
    <path x="0" y="0" d="M0,0 L725.886225,151.670321 C729.593802,152.445001 732.25,155.713561 732.25,159.501206 L732.25,928 L0,928 L0,0 Z" fill="url(#workIntroImg)"></path>
  </g>
</svg>

但是它仅在Chrome中有效-在Firefox,Safari和Edge中仅显示为空白。任何见解或在所有现代浏览器中都可以使用的替代解决方案,将不胜感激!

1 个答案:

答案 0 :(得分:1)

这可能只是拼写错误-=中缺少<image ... height"1080">。 Chrome擅长解析无效标记,其他浏览器并非总是如此。

<svg class="workIntroImage" width="696px" height="921px" viewBox="0 0 696 921">
  <defs>
    <pattern id="workIntroImg" width="1920" x="0" y="0" height="1080" patternUnits="userSpaceOnUse">
      <image xlink:href="https://www.usmagazine.com/wp-content/uploads/2017/12/147234372_the-office-zoom.jpg" x="0" y="0" width="1920" height="1080"></image>
    </pattern>
  </defs>
  <g x="0" y="0" transform="translate(-37.000000, 0.000000)">
    <path x="0" y="0" d="M0,0 L725.886225,151.670321 C729.593802,152.445001 732.25,155.713561 732.25,159.501206 L732.25,928 L0,928 L0,0 Z" fill="url(#workIntroImg)"></path>
  </g>
</svg>