【发布时间】:2017-04-21 13:30:31
【问题描述】:
我有以下 SVG:
body {
background-color: #dad9c7;
svg {
position: absolute;
width: 100%;
height: 400px;
margin: 0 auto;
display: block;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
.
<svg viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" version="1.1">
<g>
<rect width="1000" height="151" x="0" y="0" fill="#d5835b" />
<rect width="1000" height="151" x="0" y="150" fill="#d47966" />
<rect width="1000" height="126" x="0" y="300" fill="#b66961" />
<rect width="1000" height="101" x="0" y="425" fill="#d17385" />
<rect width="1000" height="101" x="0" y="525" fill="#aa617c" />
<rect width="1000" height="101" x="0" y="625" fill="#a36d8f" />
<rect width="1000" height="101" x="0" y="725" fill="#736d87" />
<rect width="1000" height="176" x="0" y="825" fill="#313d53" />
</g>
</svg>
看起来像这样:
我该如何执行以下操作?
- 缩放窗口(不是缩放)时,保持彩色条的高度相同。
- 在左右两侧的视口边缘水平拉伸彩色条带。
- 将最顶部的矩形拉伸到屏幕顶部,使视口的上三分之一为橙色,并将最底部的矩形拉伸至视口的底部,使视口的下三分之一为紫色。李>
- 始终保持“正方形”垂直居中,这已经适用于 CSS,但是处理 SVG 以解决问题时必须考虑到这一点。
这是一个外观示例:随着窗口变高,彩色矩形将停留在中间,但顶部的橙色和底部的紫色将根据视口的高度被截断。
【问题讨论】:
标签: svg