SVG viewBox 无法在负位置使用嵌套 svgs

发布于 2025-01-02 13:08:26 字数 1254 浏览 3 评论 0原文

在此示例中,绿色圆圈被切掉

<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" version="1.1" style="background-color: pink" viewBox="-300 -300 500 500">
  <svg width="500" height="500" x="0" y="0"><circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" /></svg>
  <svg width="500" height="500" x="0" y="0"><circle cx="0" cy="0" r="40" stroke="black" stroke-width="2" fill="green" /></svg>
</svg> 
</body>
</html>

请参阅:http://jsfiddle.net/sCzZT/

注意每个圆圈包裹在自己的 svg

在此示例中(无嵌套 svgs),绿色圆圈被切断

<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" version="1.1" style="background-color: pink" viewBox="-300 -300 500 500">
   <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" />
   <circle cx="0" cy="0" r="40" stroke="black" stroke-width="2" fill="green" />
</svg> 
</body>
</html>

http://jsfiddle.net/jVH9q/ 使用嵌套 svgs 时如何使绿色圆圈不被切断?

In this example, the green circle is cut off

<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" version="1.1" style="background-color: pink" viewBox="-300 -300 500 500">
  <svg width="500" height="500" x="0" y="0"><circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" /></svg>
  <svg width="500" height="500" x="0" y="0"><circle cx="0" cy="0" r="40" stroke="black" stroke-width="2" fill="green" /></svg>
</svg> 
</body>
</html>

See: http://jsfiddle.net/sCzZT/

Notice each circle is wrapped in its own svg

In this example (no nested svgs), the green circle is not cut off

<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" version="1.1" style="background-color: pink" viewBox="-300 -300 500 500">
   <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" />
   <circle cx="0" cy="0" r="40" stroke="black" stroke-width="2" fill="green" />
</svg> 
</body>
</html>

http://jsfiddle.net/jVH9q/
How do I get the green circle to not get cut off when using nested svgs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽梦忆笙歌 2025-01-09 13:08:26

内部 svg 有一个默认视口,为 0、0、500、500(x、y、宽度、高度),默认情况下,溢出该区域的任何内容都会被隐藏/剪切。

您可以做几件事...

  1. 在内部 svg 元素上添加一个 Overflow="visible" 属性
  2. 更改 x, y 值,以便圆圈位于视口内
  3. 添加一个 viewBox 以便定义一个显示该区域的显式视口你想在内部 svg 中看到。

The inner svg has a default viewport which is 0, 0, 500, 500 (x, y, width, height) and by default anything that overflows this area is hidden/clipped.

There are several things you could do...

  1. add an overflow="visible" attribute on the inner svg elements
  2. change the x, y values so that the circle is within the viewport
  3. add a viewBox so that you define an explicit viewport showing the area you want to see in the inner svg.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文