我有一个 svg 图像。svg 块本身的大小为width="64"
height="64"
,但是这个块显示的结果图像比 小很多64 х 64
,事实证明,如果将这个 svg 块插入到某个父元素中,它会占用太多空间,并且图像本身会很小。
请告诉我可以更改哪些参数以使 svg 块保持 64 x 64 不变,并且图片被放大(最好占据 svg 元素的整个空间)?
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="64"
height="64"
viewbox="0 0 64 64">
<defs>
<filter id="blur" width="200%" height="200%">
<feGaussianBlur in="SourceAlpha" stdDeviation="3"/>
<feOffset dx="0" dy="4" result="offsetblur"/>
<feComponentTransfer>
<feFuncA type="linear" slope="0.05"/>
</feComponentTransfer>
<feMerge>
<feMergeNode/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
<style type="text/css"></style>
</defs>
<g filter="url(#blur)" id="day">
<g transform="translate(32,32)">
<g class="am-weather-sun am-weather-sun-shiny am-weather-easing-ease-in-out">
<g>
<line fill="none" stroke="orange" stroke-linecap="round" stroke-width="2" transform="translate(0,9)" x1="0" x2="0" y1="0" y2="3" />
</g>
<g transform="rotate(45)">
<line fill="none" stroke="orange" stroke-linecap="round" stroke-width="2" transform="translate(0,9)" x1="0" x2="0" y1="0" y2="3" />
</g>
<g transform="rotate(90)">
<line fill="none" stroke="orange" stroke-linecap="round" stroke-width="2" transform="translate(0,9)" x1="0" x2="0" y1="0" y2="3" />
</g>
<g transform="rotate(135)">
<line fill="none" stroke="orange" stroke-linecap="round" stroke-width="2" transform="translate(0,9)" x1="0" x2="0" y1="0" y2="3" />
</g>
<g transform="rotate(180)">
<line fill="none" stroke="orange" stroke-linecap="round" stroke-width="2" transform="translate(0,9)" x1="0" x2="0" y1="0" y2="3" />
</g>
<g transform="rotate(225)">
<line fill="none" stroke="orange" stroke-linecap="round" stroke-width="2" transform="translate(0,9)" x1="0" x2="0" y1="0" y2="3" />
</g>
<g transform="rotate(270)">
<line fill="none" stroke="orange" stroke-linecap="round" stroke-width="2" transform="translate(0,9)" x1="0" x2="0" y1="0" y2="3" />
</g>
<g transform="rotate(315)">
<line fill="none" stroke="orange" stroke-linecap="round" stroke-width="2" transform="translate(0,9)" x1="0" x2="0" y1="0" y2="3" />
</g>
</g>
<circle cx="0" cy="0" fill="orange" r="5" stroke="orange" stroke-width="2"/>
</g>
</g>
</svg>
SVG 图像的大小以及它在内部占用的空间以及剩余的可用空间取决于三件事:它的绘制方式和比例
viewport
(这是 svg 标头中的宽度、高度)和viewBox
.如果 = 1,缩放取决于视口/视图框比率
在这里阅读更多
对于调整 - 调整大小,您可以使用 SVG 标头中的样式,这将显示 SVG 画布的边框
style="border:1px solid"
放大图片需要 缩小
viewBox= "0 0 64 64"
到viewbox="0 0 24 24"
<g transform="translate(12,12)">
为了使图像自适应并完全填满父块,需要将
width
height
标头中的 SVG 移除并包裹在 中div
,其尺寸必须以相对单位指定