In CSS / SVG, how to rotate each character of a word?

Here is the Jsfiddle daemon

<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; - a special character that appears as an arrow.

There is a problem in the above demonstration: the direction of the arrow in <textPath> perpendicular to <path> , while I need its direction to be the same (in parallel) as the path.

So I need to rotate 90 degrees for each character in the text &#xe55d; &#xe55d; &#xe55d; &#xe55d; &#xe55d; &#xe55d; &#xe55d; &#xe55d; (not the whole sentence).

I found this post about rotating characters, but it doesn't look perfect because it needs to "Encapsulate every letter in an element using jQuery." Maybe there is a way to make this easier in SVG?

Does anyone have any ideas on how to rotate each character of a word in a <textPath> node?

+6
source share
1 answer

Just add this style="writing-mode: tb; glyph-orientation-vertical: 180;" in text

Hope this is what you wanted:

 <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> 
+4
source

Source: https://habr.com/ru/post/989861/


All Articles