html - 将较大 svg 内的矩形水平对齐到右侧
问题描述
我有一个svg
包含一个rect
尺寸较小的内部。我希望rect
在svg
. 以下似乎不起作用:
<svg width="400"
height="110"
style="background: grey;
display: flex;
justify-content: flex-end"
>
<rect width="200"
height="50"
style="fill:rgb(0,0,255);
stroke-width:3;
stroke:rgb(0,0,0)"
/>
</svg>
当flex
它justify-content
用于svg
. 我需要明白两件事:
- 为什么
flex
样式不应用于svg
? - 如何将
rect
右对齐svg
?
先感谢您。
解决方案
用于transform: translate();
_rect
<h3>right up</h3>
<svg width="400" height="110" style="background: grey; display: flex; justify-content: flex-end">
<rect width="200" height="50" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0);transform: translate(49.5%,2%);" />
</svg>
<h3>right down</h3>
<svg width="400" height="110" style="background: grey; display: flex; justify-content: flex-end">
<rect width="200" height="50" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0);transform: translate(49.5%,52%);" />
</svg>
<h3>right center</h3>
<svg width="400" height="110" style="background: grey; display: flex; justify-content: flex-end">
<rect width="200" height="50" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0);transform: translate(49.5%,30%);" />
</svg>
编辑
采用
x="" y=""
<h3>right up</h3>
<svg width="400" height="110" style="background: grey; display: flex; justify-content: flex-end">
<rect width="200" height="50" x="198" y="2" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0);" />
</svg>
推荐阅读
- python - 试图找出一个数字中有多少位是另一个数字的倍数
- python - 如何计算循环中不同拆分的基尼系数?
- excel - VBA 代码故障:应用程序。ScreenUpdating = False 在一个按钮下调用 subs 时不起作用
- javascript - 如果数组有多个 id,则创建新对象
- c# - C# - 列表中第一个插入对象的值更改
- c - 关于将代码闪存到 ESP32 板上
- javascript - 静态成员不能引用类类型参数.ts
- mysql - MySql从另一个表中添加带有case语句的额外列以选择查询
- arrays - 如何在 c 程序中使用混合类型制作二维数组?
- javascript - 谷歌分析页面视图发送但不事件