基於https://css-tricks.com/svg-symbol-good-choice-icons/ 我有一個從svg文件中取得符號的表示形式。原始svgs具有x,y,高度和寬度等屬性。 當將svgs添加到一個svg文件並使它們成爲符號時,我發現將x,y高度和寬度屬性添加到<symbol>
是無效的svg。如何在svg符號中表示x和y
我解決了高度和寬度問題,將它們添加到<symbol>
的style屬性中,因爲支持該屬性。我的問題是,我該如何去添加x和y屬性到<symbol>
?
最終文件,僅由一個<svg>
和多個SVG的<symbol>
實施例的原始文件:
<svg style="display:none;">
<symbol id="circle" width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
Sorry, your browser does not support inline SVG.
</symbol>
</svg>
在上述:
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
Sorry, your browser does not support inline SVG.
</svg>
文件將其改爲符號之後寬度和高度不是符號的有效屬性。
的符號被用於以下方式:
<svg>
<use xlink:href="#circle" />
</svg>
然而,在上述結構中,不擴展到採取的寬度和高度。我還試圖嵌套這樣在符號內的SVG並且它也不尊重的高度和寬度:
<svg style="display:none;">
<symbol id="circle">
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
Sorry, your browser does not support inline SVG.
</svg>
</symbol>
</svg>
請在您的問題中包含一個示例,以便我們可以更好地瞭解您的意思。 –