gpt4 book ai didi

html - 在CSS/SVG中,如何旋转一个单词的每个字符?

转载 作者:太空狗 更新时间:2023-10-29 15:07:56 25 4
gpt4 key购买 nike

这是一个 Jsfiddle demo

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<svg width="100%" height="100%" viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<path id="MyPath" d="M 100 200
C 200 100 300 0 400 100
C 500 200 600 300 700 200
C 800 100 900 100 900 100" />
</defs>
<use xlink:href="#MyPath" fill="none" stroke="red" />
<text class="material-icons">
<textPath xlink:href="#MyPath">&#xe55d; &#xe55d; &#xe55d; &#xe55d;</textPath>
</text>
<!-- Show outline of the viewport using 'rect' element -->
<rect x="1" y="1" width="998" height="298" fill="none" stroke="black" stroke-width="2" />
</svg>

&#xe55d;是显示为“箭头”的特殊字符。

上面的demo有个问题:<textPath>中的箭头方向与<path>垂直 ,而我需要将其方向设置为与路径相同(平行)。

因此,我需要将文本中的每个字符旋转 90 度 &#xe55d; &#xe55d; &#xe55d; &#xe55d; (不是整个句子)..

我找到了 this post关于旋转字符,但它看起来并不理想,因为它需要“用 jQuery 将每个字母封装在一个元素中”。也许有一种方法可以在 SVG 中更轻松地做到这一点?

有没有人知道如何旋转 <textPath> 中单词的每个字符?节点?

最佳答案

只需将此 style="writing-mode: tb; glyph-orientation-vertical: 180;" 添加到 text

希望这就是你想要的:

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<svg width="100%" height="100%" viewBox="0 0 1000 300" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<path id="MyPath" d="M 100 200
C 200 100 300 0 400 100
C 500 200 600 300 700 200
C 800 100 900 100 900 100" />
</defs>
<use xlink:href="#MyPath" fill="none" stroke="red" />
<text class="material-icons" style="writing-mode: tb; glyph-orientation-vertical: 180;">
<textPath xlink:href="#MyPath">&#xe55d; &#xe55d; &#xe55d; &#xe55d;</textPath>
</text>
<!-- Show outline of the viewport using 'rect' element -->
<rect x="1" y="1" width="998" height="298" fill="none" stroke="black" stroke-width="2" />
</svg>

关于html - 在CSS/SVG中,如何旋转一个单词的每个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31091110/

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