【发布时间】:2016-11-11 07:30:22
【问题描述】:
使用 use 标签时,我的 SVG 渲染不正确。尝试使用相同的 SVG 标签而不使用 use 标签,这次我很幸运,它可以正常工作。
不幸的是,我需要 use 标签来正确渲染我的 SVG。我不知道我做错了什么。请参考下面的代码
<!-- SVG which I'm trying to reuse using `use` tag--->
<svg xmlns="http://www.w3.org/2000/svg" height="17" width="17" style="display:none">
<symbol id="check">
<defs>
<rect id="addColumn_a" width="16" height="16" y=".996" rx="1"/>
<mask id="addColumn_b" width="16" height="16" x="0" y="0" fill="white">
<use xlink:href="#addColumn_a"/>
</mask>
</defs>
<g fill="none" fill-rule="evenodd" transform="translate(0 -.996)">
<rect width="16" height="1" y="6" fill="#404040"/>
<rect width="16" height="1" y="11" fill="#404040"/>
<rect width="15" height="1" x="3.028" y="8.565" fill="#404040" transform="rotate(-90 10.528 9.065)"/>
<rect width="15.348" height="1" x="-2.141" y="8.554" fill="#5C5C5C" transform="rotate(-90 5.533 9.054)"/>
<use stroke="#404040" stroke-width="2" mask="url(#addColumn_b)" xlink:href="#addColumn_a"/>
<rect width="16" height="6" x="-5" y="5.996" fill="#19AF5C" opacity=".651" transform="rotate(-90 3 8.996)" rx="1"/>
</g>
</symbol>
</svg>
<!-- USE Link reference which is not rendering SVG properly--->
<svg height="17" width="17">
<use xlink:href="#check"></use>
</svg>
<!-- Same SVG tag just a small change removed `symbol` tag--->
<svg height="17" width="17">
<defs>
<rect id="a" width="16" height="16" y=".996" rx="1"/>
<mask id="b" width="16" height="16" x="0" y="0" fill="white">
<use xlink:href="#a"/>
</mask>
</defs>
<g fill="none" fill-rule="evenodd" transform="translate(0 -.996)">
<rect width="16" height="1" y="6" fill="#404040"/>
<rect width="16" height="1" y="11" fill="#404040"/>
<rect width="15" height="1" x="3.028" y="8.565" fill="#404040" transform="rotate(-90 10.528 9.065)"/>
<rect width="15.348" height="1" x="-2.141" y="8.554" fill="#5C5C5C" transform="rotate(-90 5.533 9.054)"/>
<use stroke="#404040" stroke-width="2" mask="url(#b)" xlink:href="#a"/>
<rect width="16" height="6" x="-5" y="5.996" fill="#19AF5C" opacity=".651" transform="rotate(-90 3 8.996)" rx="1"/>
</g>
</svg>
P.S 我使用工具渲染了这个 SVG 代码,不是手写代码
【问题讨论】:
-
“未正确渲染”是什么意思?你指的是外面的粗线吗?