Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何重用svg元素并调整大小_Svg - Fatal编程技术网

如何重用svg元素并调整大小

如何重用svg元素并调整大小,svg,Svg,我有一个长方形 <rect id="greenRect" fill="lightgreen" height="20" width="20"/> <!-- transformation are applied right-to-left --> <use href="#greenRect" transform="translate(0 150) scale(2.5)"/> 现在我想重用rect,但要使它更大 大小(高度/宽度)似乎不会被原始元素覆盖 如何实

我有一个长方形

<rect id="greenRect" fill="lightgreen" height="20" width="20"/>
<!-- transformation are applied right-to-left -->
<use href="#greenRect" transform="translate(0 150) scale(2.5)"/>

现在我想重用rect,但要使它更大

大小(高度/宽度)似乎不会被原始
元素覆盖


如何实现这样的目标?

解决方案1:使用
viewBox
属性将rect包装在

<symbol id="greenRect" viewBox="0 0 20 20">
    <rect fill="lightgreen" height="20" width="20"/>
</symbol>
<!-- symbols are not rendered, so if you want to see your original,
     you have to also use it -->
<use href="#greenRect" height="20" width="20"/>
<use href="#greenRect" y="150" height="50" width="50"/>

解决方案2:缩放并平移矩形

<rect id="greenRect" fill="lightgreen" height="20" width="20"/>
<!-- transformation are applied right-to-left -->
<use href="#greenRect" transform="translate(0 150) scale(2.5)"/>

解决方案1:使用
viewBox
属性将rect包装在

<symbol id="greenRect" viewBox="0 0 20 20">
    <rect fill="lightgreen" height="20" width="20"/>
</symbol>
<!-- symbols are not rendered, so if you want to see your original,
     you have to also use it -->
<use href="#greenRect" height="20" width="20"/>
<use href="#greenRect" y="150" height="50" width="50"/>

解决方案2:缩放并平移矩形

<rect id="greenRect" fill="lightgreen" height="20" width="20"/>
<!-- transformation are applied right-to-left -->
<use href="#greenRect" transform="translate(0 150) scale(2.5)"/>


我特别喜欢符号方法。谢谢我特别喜欢符号方法。谢谢