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

Han*_*Sun 6 html css svg transform css-transforms

这是一个Jsfiddle 演示

<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>
Run Code Online (Sandbox Code Playgroud)

&#xe55d; 是一个特殊字符,显示为"箭头".

有在上述演示了一个问题:箭头的方向在<textPath>垂直<path>,虽然我需要设置其方向是相同的(在平行)作为路径.

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

我发现这篇关于旋转字符的帖子,但它看起来并不理想,因为它需要"使用jQuery封装元素中的每个字母".也许有一种方法可以更容易地在SVG中做到这一点?

有没有人有关于如何旋转<textPath>节点中单词的每个字符的想法?

Sid*_*ril 4

只需将其添加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>
Run Code Online (Sandbox Code Playgroud)