比方说,我有如下所示的SVG,如何在图像顶部添加10px填充?我尝试使用style="padding-top: 10px"
和transform="translate(0,10px)"
,但最终都将底部裁剪10像素。调整视口尺寸并不能解决我的问题。
请注意,我想在SVG代码中执行此操作,而不要使用外部样式。我以为这是一个容易的调整,但是不可以。
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 440.11 132.63">
<path fill="#fcaf17" fill-rule="evenodd" d="M273.04 103.72c-25.57 18.87-62.64 28.9-94.57 28.9A171.14 171.14 0 0 1 62.95 88.56c-2.38-2.16-.25-5.12 2.63-3.45 32.89 19.2 73.6 30.68 115.6 30.68a229.73 229.73 0 0 0 88.16-18.05c4.32-1.83 7.95 2.86 3.72 6"/>
<path fill="#fcaf17" fill-rule="evenodd" d="M283.68 91.57c-3.27-4.19-21.62-2-29.87-1-2.49.3-2.87-1.88-.62-3.45 14.63-10.29 38.61-7.31 41.4-3.88s-.73 27.52-14.45 39c-2.11 1.77-4.12.81-3.18-1.51 3.09-7.71 10-25 6.72-29.16"/>
<path fill="#231f20" fill-rule="evenodd" d="M254.4 14.48v-10a2.48 2.48 0 0 1 2.53-2.54h44.78a2.5 2.5 0 0 1 2.58 2.53v8.56c0 1.43-1.22 3.31-3.38 6.29l-23.18 33.12c8.6-.21 17.72 1.08 25.53 5.48a4.54 4.54 0 0 1 2.37 3.9v10.66c0 1.47-1.6 3.17-3.28 2.27a51.59 51.59 0 0 0-47.31.1c-1.57.82-3.19-.85-3.19-2.32V62.42a12 12 0 0 1 1.66-6.87L280.38 17h-23.39a2.49 2.49 0 0 1-2.59-2.52M91.08 76.88H77.46a2.56 2.56 0 0 1-2.44-2.3V4.66a2.57 2.57 0 0 1 2.64-2.51h12.68a2.56 2.56 0 0 1 2.48 2.35v9.13h.26C96.38 4.8 102.61.68 111 .68s13.86 4.12 17.68 12.95C131.98 4.8 139.48.68 147.49.68a19.32 19.32 0 0 1 15.77 7.63c4.32 5.87 3.44 14.41 3.44 21.92v44.11a2.57 2.57 0 0 1-2.63 2.52h-13.62a2.55 2.55 0 0 1-2.44-2.51V37.31c0-2.94.25-10.29-.39-13.09-1-4.71-4.07-6-8-6a9 9 0 0 0-8.14 5.74c-1.41 3.49-1.3 9.35-1.3 13.35v37.06a2.57 2.57 0 0 1-2.63 2.52h-13.58a2.55 2.55 0 0 1-2.44-2.51V37.31c0-7.79 1.26-19.27-8.4-19.27s-9.41 11.18-9.41 19.27v37.06a2.56 2.56 0 0 1-2.62 2.52M342.83.67c20.22 0 31.15 17.37 31.15 39.43 0 21.33-12.08 38.25-31.15 38.25-19.84 0-30.64-17.36-30.64-39 0-21.78 10.93-38.7 30.64-38.7m.13 14.27c-10 0-10.68 13.68-10.68 22.21s-.12 26.79 10.55 26.79S353.9 49.2 353.9 40.23c0-5.89-.26-12.95-2-18.54-1.53-4.85-4.58-6.77-8.9-6.77M400.18 76.88h-13.55a2.56 2.56 0 0 1-2.44-2.51V4.42a2.59 2.59 0 0 1 2.63-2.27h12.63a2.58 2.58 0 0 1 2.42 1.95v10.69h.25C405.94 5.23 411.28.68 420.68.68c6.11 0 12.08 2.2 15.9 8.24 3.57 5.58 3.57 15 3.57 21.77v44a2.6 2.6 0 0 1-2.62 2.21h-13.68a2.58 2.58 0 0 1-2.43-2.21v-38c0-7.64.9-18.82-8.52-18.82a8.9 8.9 0 0 0-7.88 5.59c-1.9 4.26-2.17 8.52-2.17 13.23v37.65a2.6 2.6 0 0 1-2.65 2.52M218.71 43.49c0 5.31.12 9.73-2.55 14.45-2.17 3.83-5.6 6.19-9.43 6.19-5.23 0-8.29-4-8.29-9.88 0-11.59 10.41-13.7 20.27-13.7zm13.73 33.21a2.8 2.8 0 0 1-3.21.32c-4.53-3.76-5.34-5.5-7.81-9.07-7.48 7.61-12.78 9.9-22.46 9.9-11.47 0-20.39-7.08-20.39-21.24 0-11.05 6-18.57 14.52-22.26 7.4-3.24 17.72-3.83 25.62-4.71v-1.77c0-3.26.25-7.09-1.66-9.88-1.65-2.52-4.84-3.54-7.65-3.54-5.19 0-9.8 2.66-10.95 8.18a2.85 2.85 0 0 1-2.36 2.5l-13.2-1.43a2.39 2.39 0 0 1-2-2.84c3-16 17.5-20.86 30.46-20.86 6.62 0 15.29 1.77 20.51 6.78 6.63 6.19 6 14.45 6 23.45v21.22c0 6.38 2.65 9.17 5.15 12.62.86 1.24 1.06 2.71-.05 3.61a531.33 531.33 0 0 0-10.48 9.06zM40.18 43.49c0 5.31.12 9.73-2.55 14.45-2.17 3.83-5.6 6.19-9.43 6.19-5.23 0-8.29-4-8.29-9.88 0-11.59 10.42-13.7 20.27-13.7zM53.91 76.7a2.8 2.8 0 0 1-3.21.32c-4.53-3.76-5.34-5.5-7.82-9.07-7.47 7.61-12.76 9.9-22.45 9.9C8.97 77.85.04 70.77.04 56.61c0-11.05 6-18.57 14.53-22.26 7.39-3.24 17.71-3.83 25.61-4.71v-1.77c0-3.26.26-7.09-1.66-9.88-1.65-2.52-4.84-3.54-7.65-3.54-5.19 0-9.81 2.66-10.94 8.18a2.87 2.87 0 0 1-2.36 2.5L4.37 23.7a2.4 2.4 0 0 1-2-2.84C5.37 4.86 19.87 0 32.83 0c6.62 0 15.29 1.77 20.52 6.78 6.63 6.19 6 14.45 6 23.45v21.22c0 6.38 2.65 9.17 5.14 12.62.87 1.24 1.06 2.71 0 3.61a599.2 599.2 0 0 0-10.44 9.06z"/>
</svg>
答案 0 :(得分:0)
只需更改viewBox。您可能需要尝试一下才能找到所需的值。
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -20 440.11 152.63">
<path fill="#fcaf17" fill-rule="evenodd" d="M273.04 103.72c-25.57 18.87-62.64 28.9-94.57 28.9A171.14 171.14 0 0 1 62.95 88.56c-2.38-2.16-.25-5.12 2.63-3.45 32.89 19.2 73.6 30.68 115.6 30.68a229.73 229.73 0 0 0 88.16-18.05c4.32-1.83 7.95 2.86 3.72 6"/>
<path fill="#fcaf17" fill-rule="evenodd" d="M283.68 91.57c-3.27-4.19-21.62-2-29.87-1-2.49.3-2.87-1.88-.62-3.45 14.63-10.29 38.61-7.31 41.4-3.88s-.73 27.52-14.45 39c-2.11 1.77-4.12.81-3.18-1.51 3.09-7.71 10-25 6.72-29.16"/>
<path fill="#231f20" fill-rule="evenodd" d="M254.4 14.48v-10a2.48 2.48 0 0 1 2.53-2.54h44.78a2.5 2.5 0 0 1 2.58 2.53v8.56c0 1.43-1.22 3.31-3.38 6.29l-23.18 33.12c8.6-.21 17.72 1.08 25.53 5.48a4.54 4.54 0 0 1 2.37 3.9v10.66c0 1.47-1.6 3.17-3.28 2.27a51.59 51.59 0 0 0-47.31.1c-1.57.82-3.19-.85-3.19-2.32V62.42a12 12 0 0 1 1.66-6.87L280.38 17h-23.39a2.49 2.49 0 0 1-2.59-2.52M91.08 76.88H77.46a2.56 2.56 0 0 1-2.44-2.3V4.66a2.57 2.57 0 0 1 2.64-2.51h12.68a2.56 2.56 0 0 1 2.48 2.35v9.13h.26C96.38 4.8 102.61.68 111 .68s13.86 4.12 17.68 12.95C131.98 4.8 139.48.68 147.49.68a19.32 19.32 0 0 1 15.77 7.63c4.32 5.87 3.44 14.41 3.44 21.92v44.11a2.57 2.57 0 0 1-2.63 2.52h-13.62a2.55 2.55 0 0 1-2.44-2.51V37.31c0-2.94.25-10.29-.39-13.09-1-4.71-4.07-6-8-6a9 9 0 0 0-8.14 5.74c-1.41 3.49-1.3 9.35-1.3 13.35v37.06a2.57 2.57 0 0 1-2.63 2.52h-13.58a2.55 2.55 0 0 1-2.44-2.51V37.31c0-7.79 1.26-19.27-8.4-19.27s-9.41 11.18-9.41 19.27v37.06a2.56 2.56 0 0 1-2.62 2.52M342.83.67c20.22 0 31.15 17.37 31.15 39.43 0 21.33-12.08 38.25-31.15 38.25-19.84 0-30.64-17.36-30.64-39 0-21.78 10.93-38.7 30.64-38.7m.13 14.27c-10 0-10.68 13.68-10.68 22.21s-.12 26.79 10.55 26.79S353.9 49.2 353.9 40.23c0-5.89-.26-12.95-2-18.54-1.53-4.85-4.58-6.77-8.9-6.77M400.18 76.88h-13.55a2.56 2.56 0 0 1-2.44-2.51V4.42a2.59 2.59 0 0 1 2.63-2.27h12.63a2.58 2.58 0 0 1 2.42 1.95v10.69h.25C405.94 5.23 411.28.68 420.68.68c6.11 0 12.08 2.2 15.9 8.24 3.57 5.58 3.57 15 3.57 21.77v44a2.6 2.6 0 0 1-2.62 2.21h-13.68a2.58 2.58 0 0 1-2.43-2.21v-38c0-7.64.9-18.82-8.52-18.82a8.9 8.9 0 0 0-7.88 5.59c-1.9 4.26-2.17 8.52-2.17 13.23v37.65a2.6 2.6 0 0 1-2.65 2.52M218.71 43.49c0 5.31.12 9.73-2.55 14.45-2.17 3.83-5.6 6.19-9.43 6.19-5.23 0-8.29-4-8.29-9.88 0-11.59 10.41-13.7 20.27-13.7zm13.73 33.21a2.8 2.8 0 0 1-3.21.32c-4.53-3.76-5.34-5.5-7.81-9.07-7.48 7.61-12.78 9.9-22.46 9.9-11.47 0-20.39-7.08-20.39-21.24 0-11.05 6-18.57 14.52-22.26 7.4-3.24 17.72-3.83 25.62-4.71v-1.77c0-3.26.25-7.09-1.66-9.88-1.65-2.52-4.84-3.54-7.65-3.54-5.19 0-9.8 2.66-10.95 8.18a2.85 2.85 0 0 1-2.36 2.5l-13.2-1.43a2.39 2.39 0 0 1-2-2.84c3-16 17.5-20.86 30.46-20.86 6.62 0 15.29 1.77 20.51 6.78 6.63 6.19 6 14.45 6 23.45v21.22c0 6.38 2.65 9.17 5.15 12.62.86 1.24 1.06 2.71-.05 3.61a531.33 531.33 0 0 0-10.48 9.06zM40.18 43.49c0 5.31.12 9.73-2.55 14.45-2.17 3.83-5.6 6.19-9.43 6.19-5.23 0-8.29-4-8.29-9.88 0-11.59 10.42-13.7 20.27-13.7zM53.91 76.7a2.8 2.8 0 0 1-3.21.32c-4.53-3.76-5.34-5.5-7.82-9.07-7.47 7.61-12.76 9.9-22.45 9.9C8.97 77.85.04 70.77.04 56.61c0-11.05 6-18.57 14.53-22.26 7.39-3.24 17.71-3.83 25.61-4.71v-1.77c0-3.26.26-7.09-1.66-9.88-1.65-2.52-4.84-3.54-7.65-3.54-5.19 0-9.81 2.66-10.94 8.18a2.87 2.87 0 0 1-2.36 2.5L4.37 23.7a2.4 2.4 0 0 1-2-2.84C5.37 4.86 19.87 0 32.83 0c6.62 0 15.29 1.77 20.52 6.78 6.63 6.19 6 14.45 6 23.45v21.22c0 6.38 2.65 9.17 5.14 12.62.87 1.24 1.06 2.71 0 3.61a599.2 599.2 0 0 0-10.44 9.06z"/>
</svg>
答案 1 :(得分:0)
我必须将svg文件转换为base 64并将其插入具有样式的图像标签内:
<img alt="logo" style="padding-top:10px" src="data:image/svg+xml;base64,
PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA
0NDAuMTEgMTMyLjYzIj4NCiAgPHBhdGggZmlsbD0iI2ZjYWYxNyIgZmlsbC1ydWxlPSJldm
Vub2RkIiBkPSJNMjczLjA0IDEwMy43MmMtMjUuNTcgMTguODctNjIuNjQgMjguOS05NC41N
yAyOC45QTE3MS4xNCAxNzEuMTQgMCAwIDEgNjIuOTUgODguNTZjLTIuMzgtMi4xNi0uMjUt
NS4xMiAyLjYzLTMuNDUgMzIuODkgMTkuMiA3My42IDMwLjY4IDExNS42IDMwLjY4YTIyOS4
3MyAyMjkuNzMgMCAwIDAgODguMTYtMTguMDVjNC4zMi0xLjgzIDcuOTUgMi44NiAzLjcyID
YiLz4NCiAgPHBhdGggZmlsbD0iI2ZjYWYxNyIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNM
jgzLjY4IDkxLjU3Yy0zLjI3LTQuMTktMjEuNjItMi0yOS44Ny0xLTIuNDkuMy0yLjg3LTEu
ODgtLjYyLTMuNDUgMTQuNjMtMTAuMjkgMzguNjEtNy4zMSA0MS40LTMuODhzLS43MyAyNy4
1Mi0xNC40NSAzOWMtMi4xMSAxLjc3LTQuMTIuODEtMy4xOC0xLjUxIDMuMD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