gpt4 book ai didi

css - 使用 CSS 旋转 SVG 路径

转载 作者:技术小花猫 更新时间:2023-10-29 10:24:57 25 4
gpt4 key购买 nike

我有这个 SVG:

* {
background: #e1e1e1;
}
<svg class="decor" height="100%" preserveaspectratio="none" version="1.1" viewbox="0 0 100 100" width="100%" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0 L100 100 L0 100" stroke-width="0"></path>
</svg>

如何将它旋转180度?!

DEMO

最佳答案

只需使用元素类型选择器并向其添加 transform: rotate(180deg) 属性,如下面的代码片段所示。

* {
background: #e1e1e1;
}
svg {
transform: rotate(180deg);
}
<svg class="decor" height="100%" preserveaspectratio="none" version="1.1" viewbox="0 0 100 100" width="100%" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0 L100 100 L0 100" stroke-width="0"></path>
</svg>


或者,如果您只想旋转 path 而不是 svg 本身,则包括如下所示的 transform-origin片段:

* {
background: #e1e1e1;
}
path {
transform: rotate(180deg);
transform-origin: 50% 50%;
}
<svg class="decor" height="100%" preserveaspectratio="none" version="1.1" viewbox="0 0 100 100" width="100%" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0 L100 100 L0 100" stroke-width="0"></path>
</svg>

关于css - 使用 CSS 旋转 SVG 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33186431/

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