gpt4 book ai didi

html - svg 元素的位置

转载 作者:行者123 更新时间:2023-11-28 10:23:57 27 4
gpt4 key购买 nike

我试图在这个绿色矩形前面放置一个多边形,这样它看起来就像巴西国旗。我的代码:

<svg class="green"
version="1.1"
baseProfile="full"
xmlns="http://www.w3.org/2000/svg">
<rect x=0 y=0 height=450 width=800 fill="#009B3A"/>
<polygon x=0 y=0 points="400,430 600,215 400,30 200,215" fill="#FEDF00"/>
</svg>

有趣的是,多边形元素没有出现在矩形的前面,这让我很困惑。我制作了一个丹麦国旗 svg,它看起来很好,白色的 strip 出现在红色矩形的前面,正如它们应该的那样,我的丹麦国旗代码:

<svg 
version="1.1"
baseProfile="full"
xmlns="http://www.w3.org/2000/svg">
<rect x=0 y=0 height=450 width=800 fill="#C60C30"/>
<rect x=200 y=0 height=450 width=60 fill="#FFF"/>
<rect x=0 y=175 height=60 width=800 fill="#FFF"/>
</svg>

我希望它能以某种方式对巴西国旗做同样的事情

最佳答案

添加了 viewBox="0 0 450 800"transform="translate(-175 0)"

这将为黄色钻石设置正确的位置

<svg class="green"
version="1.1"
baseProfile="full"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 450 800">
<rect x=0 y=0 height=450 width=800 fill="#009B3A"/>
<polygon transform="translate(-175 0)" points="400,430 600,215 400,30 200,215" fill="#FEDF00"/>
</svg>

关于html - svg 元素的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59328618/

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