【问题标题】:svg rounded-corner clipping in firefox (works fine in ie9 and chrome)svg 在 Firefox 中的圆角剪裁(在 ie9 和 chrome 中工作正常)
【发布时间】:2012-06-09 22:46:43
【问题描述】:

如果有人能帮助我解决以下问题,我将不胜感激:

当圆角添加到 svg 画布时,chrome 和 ie9 都可以正确执行剪切。然而,Firefox (v13.0) 会忽略圆角。我可以在 svg 中手动进行剪辑,但我想知道是否有更好的解决方案。

代码如下:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <svg id="paper" version="1.1" width="300" height="300" style="border-radius: 20px; background-color: red;">
        <rect x="0" y="0" width="400" height="400" fill="blue">
    </svg>
</body>
</html>

谢谢!

【问题讨论】:

标签: css firefox svg rounded-corners


【解决方案1】:

您也可以让 svg 矩形具有相同的圆角。

<svg id="paper" version="1.1" width="300" height="300" style="border-radius: 20px; background-color: red;">
  <rect id="background" width="100%" height="100%" rx="20" fill="red"/>
</svg>

或者如果你需要剪辑,就像你建议的那样:

<!DOCTYPE html>
<html>
<body>
<svg id="paper" version="1.1" width="300" height="300" clip-path="url(#clip)">
    <defs>
        <clipPath id="clip">
            <rect id="background" width="100%" height="100%" rx="20" fill="red"/>
        </clipPath>
    </defs>
    <rect width="100%" height="100%" fill="red"/>
</svg>
</body>
</html>

【讨论】:

  • 抱歉,我应该解释一下我的目标。我正在做一个需要缩放和平移的项目,所以从容器中伸出的东西是不可避免的。我可能会选择剪裁。感谢您的代码!
猜你喜欢
  • 2014-08-12
  • 2011-08-23
  • 2015-05-06
  • 2017-01-12
  • 2012-08-28
  • 1970-01-01
  • 1970-01-01
  • 2021-12-30
  • 1970-01-01
相关资源
最近更新 更多