2017-06-15 86 views
0

我有兩個SVG文件。我試圖將rect.svg的內容鏈接到tst_use.svg。 tst_use.svg的內容,SVG Xlink將不會鏈接到帶有xlink的外部文件:href在<use>標籤

<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.1" id="svg_hom_img" width="508" height="438"> 
<use x="0" y="0" id="us_g1_0" width="508" height="438" xlink:href="rect.svg"/> 
</svg> 

和rect.svg的內容,

<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.1" id="svg_hom_img" width="508" height="438"> 
<rect x="0" y="1" width="250" height="250" id="BackDrop" pointer-events="all" style="opacity:1;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:2;  stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:0"/> 
</svg> 

當然,這兩個文件是在同一目錄下。我嘗試了一些組合。代碼工作內聯。 rect.svg顯示在瀏覽器中。我也可以用javascript拼湊文件。其他人使用這種語法。爲什麼不能tst_use.svg xlink到rect.svg?

+0

無法指向SVG 1.1中的完整文件,它必須指向該文件中的某個內容。如果您想要一個完整的文件,請使用標籤。 –

回答

0

使用羅伯特Longson的評論,我也要用同樣rect.svg改變test_use.svg到,

<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0" id="svg_hom_img" width="508" height="438"> 
    <use x="0" y="0" id="us_g1_0" width="508" height="438" xlink:href="rect.svg#BackDrop"/> 
</svg> 

中的問題。這在Firefox中顯示矩形,但在Chrome中不顯示。看來,JavaScript是最好的解決方案。

相關問題