我正在尝试减少http请求并使用svg代替css3内容进行一些小实验...无法将此HTML SVG设置为动态扩展。理想情况下,我想将它的宽度和高度设置为50%,并让浏览器在窗口调整大小时完成其余工作。
以下是代码:
<svg xmlns="http://www.w3.org/2000/svg">
<title>Daniel Hutchinson</title>
<g>
<path d="m133.936,182.53101h-8.41701v77.21298h8.05002c21.40799,0 39.70398,-11.70999 39.70398,-38.60599c0.00101,-24.70099 -16.28299,-38.60699 -39.33699,-38.60699z" clip-rule="evenodd" fill-rule="evenodd"/>
<path fill="black" d="m218.448,0c-120.646,0 -218.448,97.802 -218.448,218.448s97.802,218.448 218.448,218.448s218.448,-97.802 218.448,-218.448s-97.80301,-218.448 -218.448,-218.448zm-77.925,290.117h-50.86501v-137.95801h50.86501c38.423,0 70.07701,30.19 70.07701,68.97897s-31.83701,68.97903 -70.07701,68.97903zm210.22499,0h-35.862v-56.53699h-51.78v56.53699h-35.862v-137.95801h35.862v53.24402h51.78v-53.24402h35.862v137.95801l0,0z" clip-rule="evenodd" fill-rule="evenodd"/>
</g>
</svg>
答案 0 :(得分:1)
浏览器不会正确缩放SVG图像,除非你给它们viewBox
,我快速到达这些数字experimenting in JSFiddle,你可以用一点点努力来计算出所需的确切值:< / p>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-10 -10 600 600">
您还可以尝试指定width
和height
属性,不同的浏览器会以不同的方式响应它们,尤其是当您使用CSS调整大小时。前一阵子我敲了a test page which tried all the combinations when embedding SVG as an image,值得比较(例如)Firefox和Chrome的不同结果。我希望在CSS中使用SVG可以得到类似的结果。