html - SVG 百分比坐标已关闭
问题描述
我有三个 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>
解决方案
因为您在 90% 处开始绘制第二个蓝色框,而您真的想在 90% 处结束绘制。通过将第二个蓝色框的 viewBox 设置为:
viewBox="20 0 20 20"
推荐阅读
- java - 取消对 JAVA JSP 的预订
- wordpress - 如何在 Github 上安装 WordPress 网站
- swift - 在 Swift 4 上使用 Starscream 通过 Websocket 发送文件
- python - 熊猫数据框减法
- reporting-services - 数据集查询更改时 SSRS 更新报告
- asp.net - ASP.NET MVC 5 - 从同一网络中的电话/PC 访问 localhost
- java - 从 pentaho 勺子读取 jboss 访问日志
- timezone - 使用 Moment.js 将 ISO 字符串转换为 PST
- swift - RxSwift 中的乐观 UI 更新
- matlab - 在matlab中从几分钟到几小时重新采样多个数据列