为什么SVG viewbox属性仅适用于内联SVG?

时间:2017-04-12 08:39:35

标签: svg

我下载了一些16x16 SVG图标,这些图标使用了viewbox属性来缩放原始代码,以便在下载时适合16x16画布。现在我遇到的是我无法从外部文件中插入SVG,因为viewbox属性只是没有工作。如果我将SVG代码内联,那么它就可以工作。

我错过了什么,或者这是怎么回事?

这是代码。

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" height="16" viewbox="0 0 48 48" width="16">
  <path clip-rule="evenodd" d="M37,47H11c-2.209,0-4-1.791-4-4V5c0-2.209,1.791-4,4-4h18.973
    c0.002,0,0.005,0,0.007,0h0.02H30c0.32,0,0.593,0.161,0.776,0.395l9.829,9.829C40.84,11.407,41,11.68,41,12l0,0v0.021                                                                                                 
    c0,0.002,0,0.003,0,0.005V43C41,45.209,39.209,47,37,47z M31,4.381V11h6.619L31,4.381z M39,13h-9c-0.553,0-1-0.448-1-1V3H11
    C9.896,3,9,3.896,9,5v38c0,1.104,0.896,2,2,2h26c1.104,0,2-0.896,2-2V13z M33,39H15c-0.553,0-1-0.447-1-1c0-0.552,0.447-1,1-1h18 
    c0.553,0,1,0.448,1,1C34,38.553,33.553,39,33,39z M33,31H15c-0.553,0-1-0.447-1-1c0-0.552,0.447-1,1-1h18c0.553,0,1,0.448,1,1
    C34,30.553,33.553,31,33,31z M33,23H15c-0.553,0-1-0.447-1-1c0-0.552,0.447-1,1-1h18c0.553,0,1,0.448,1,1C34,22.553,33.553,23,33,23  z" 
    fill-rule="evenodd"/>
</svg>

1 个答案:

答案 0 :(得分:0)

请注意,它viewBox不是viewbox - 浏览器可能会为您节省时间,但并非总是如此。

有关详细信息,请参阅以下内容: https://jsfiddle.net/t88pLgbb/4/