【发布时间】:2018-05-15 16:28:07
【问题描述】:
我在另一个 SVG 中嵌套了三个 SVG。第一个应该是流动的和伸展的,所以preserveAspectRatio 是none。另外两个设置为10% 和90% 的x 值。但是,如果您调整页面大小,您会发现它们与左侧和右侧的距离不同。为什么?
我希望看到左边的距离与右边的距离相同。
.box {
width: 60vw;
border: 1px dashed lightgray;
}
svg {
overflow: visible;
}
<div class="box">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="50">
<svg viewBox="0 0 2 2" preserveAspectRatio="none">
<rect x="0" width="2" height="1" fill="#DDDDDD" />
</svg>
<svg x="10%" viewBox="0 0 20 20" preserveAspectRatio="xMinYMid">
<rect x="0" y="0" width="10" height="10" fill="#7FDBFF" />
</svg>
<svg x="90%" viewBox="0 0 20 20" preserveAspectRatio="xMinYMid">
<rect x="0" y="0" width="10" height="10" fill="#7FDBFF" />
</svg>
</svg>
</div>
【问题讨论】:
标签: html css svg responsive