gpt4 book ai didi

html - SVG 对齐到父元素的右下角

转载 作者:行者123 更新时间:2023-11-28 03:33:24 26 4
gpt4 key购买 nike

我正在尝试在 SVG 中绘制一个矩形(300x300 像素)并在父矩形(10x10 像素)的每个角对齐 4 个较小的矩形,但每个小的子矩形都具有父矩形的完整大小。

<svg width="300" height="300">
<svg height="10" width="10" />
<svg height="10" width="10" />
<svg height="10" width="10" />
<svg height="10" width="10" />
</svg>

您可以在这里查看我的结果:http://jsfiddle.net/8tY3b/

如果我将内部 SVG 元素的宽度或高度设置为 10px,它适用于除右下角以外的所有边缘。

有没有办法让子元素对齐到父元素的右下角?

最佳答案

您想嵌入 svg 元素还是绘制矩形?如果您对后者感到满意,请继续:

<?xml version="1.0" encoding="utf-8"?>
<!-- SO: http://stackoverflow.com/questions/15495978/svg-circled-text-on-textpath-center-align -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
width="15cm" height="15cm"
viewBox="0 0 300 300"
preserveAspectRatio="none"
style="background-color:white; border: solid 1px black;"
>
<rect fill="green" stroke="blue" stroke-width="2" height="10" width="10" x="0" y="0"/>
<rect fill="green" stroke="blue" stroke-width="2" height="10" width="10" x="290" y="0"/>
<rect fill="green" stroke="blue" stroke-width="2" height="10" width="10" x="0" y="290"/>
<rect fill="green" stroke="blue" stroke-width="2" height="10" width="10" x="290" y="290"/>
</svg>

preserveAspectRatio 属性的值 none 允许任意缩放。

关于html - SVG 对齐到父元素的右下角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16169342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com