我在SVG中完成了一个表格,并且我想动态地用数据填充它。这意味着我不知道文本需要多少空间,并且我想要剪切或隐藏重叠的文本。我如何在SVG中做到这一点?如何限制或剪切SVG中的文本?
我对SVG的HTML文档的样子:
<!DOCTYPE html>
<html>
<body>
<svg>
<text x="100" y="100">Orange</text> <text x="160" y="100">12</text>
<text x="100" y="115">Pear</text> <text x="160" y="115">7</text>
<text x="100" y="130">Banana</text> <text x="160" y="130">9</text>
<text x="100" y="145">Pomegranate</text><text x="160" y="145">2</text>
<line x1="157" y1="85" x2="157" y2="155" style="stroke:rgb(100,100,100)"/>
</svg>
</body>
</html>
,这将渲染到:
有什么办法,我可以夹在我的文字我SVG- “表” ?
实施的解决方案从埃里克的回答是:
<!DOCTYPE html>
<html>
<body>
<svg>
<text x="10" y="20" clip-path="url(#clip1)">Orange</text>
<text x="10" y="35" clip-path="url(#clip1)">Pear</text>
<text x="10" y="50" clip-path="url(#clip1)">Banana</text>
<text x="10" y="65" clip-path="url(#clip1)">Pomegranate</text>
<text x="70" y="20">12</text>
<text x="70" y="35">7</text>
<text x="70" y="50">9</text>
<text x="70" y="65">2</text>
<line x1="67" y1="5" x2="67" y2="75" style="stroke:rgb(100,100,100)"/>
<clipPath id="clip1">
<rect x="5" y="5" width="57" height="90"/>
</clipPath>
</svg>
</body>
</html>
你可以在上面的图片中看到它的剪辑在字母'a'的中间。更喜欢textPath而不是http://stackoverflow.com/a/9249966/592792 –