css - 如何使 SVG 不拉伸?
问题描述
我有一个 SVG 背景,并且在 SVG 背景顶部有一个固定的白框。当我使浏览器尺寸高度变大时,SVG 也会扩展,从而在白框和 svg 之间产生巨大的空间。如何阻止 svg 从浏览器大小扩展?
<?xml version="1.0" encoding="UTF-8"?>
<svg viewBox="0 0 1441 668" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: sketchtool 60.1 (101010) - https://sketch.com -->
<desc>Created with sketchtool.</desc>
<g id="Asset-Artboard-Page" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="bg-bg-new" transform="translate(0.975610, 0.000000)">
<g id="bg-geo" transform="translate(0.000000, 0.000000)">
<rect id="bg" fill="#279BE8" x="0" y="0" width="1440" height="668"></rect>
<polygon id="green" fill="#44CF50" points="680 668 -7.54951657e-14 320 0 668"></polygon>
<polygon id="blue-light" fill="#FFFFFF" points="364 0 0 264 0 0"></polygon>
<polygon id="blue-dark" fill="#103C63" points="136 668 798 188 1440 518 1440 668"></polygon>
<polygon id="blue-light" fill="#E6F9FC" points="987 668 1440 340 1440 668"></polygon>
</g>
</g>
</g>
</svg>
解决方案
svg
在容器上使用固定的宽度和高度。svg
如果未设置宽度和高度,则采用父级的尺寸。
<?xml version="1.0" encoding="UTF-8"?>
<svg viewBox="0 0 1441 668" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" height="300">
<!-- Generator: sketchtool 60.1 (101010) - https://sketch.com -->
<desc>Created with sketchtool.</desc>
<g id="Asset-Artboard-Page" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="bg-bg-new" transform="translate(0.975610, 0.000000)">
<g id="bg-geo" transform="translate(0.000000, 0.000000)">
<rect id="bg" fill="#279BE8" x="0" y="0" width="1440" height="668"></rect>
<polygon id="green" fill="#44CF50" points="680 668 -7.54951657e-14 320 0 668"></polygon>
<polygon id="blue-light" fill="#FFFFFF" points="364 0 0 264 0 0"></polygon>
<polygon id="blue-dark" fill="#103C63" points="136 668 798 188 1440 518 1440 668"></polygon>
<polygon id="blue-light" fill="#E6F9FC" points="987 668 1440 340 1440 668"></polygon>
</g>
</g>
</g>
</svg>
推荐阅读
- python - 如何编写一个Ceaser Cipher Python
- django - 如果没有定义 self.kwargs 来自哪里的问题?特别是在 django 代码库中的 SingleObjectMixin 类中
- python-3.x - statsmodels.api 和 scipy.stats 没有产生合适的拟合
- c# - 如何反序列化对对象列表的 JSON 响应
- java - 在 Java 中使用 Selenium 单击动态下拉 div
- reactjs - REACT 16 中的 React 组件中的错误处理
- android - 如何更改 ViewPager 中特定页面的 textView 的文本?
- python - 如何分配变量以从数组中选择?
- pyspark - 我如何在 jupyter notebook 上的 pyspark 中进行测试
- c# - 仅更改对象的 X 轴比例