I am trying to create vertically oriented text with a right-to-left gradient using the code below. However, the text is being displayed incorrectly.
text {
writing-mode: vertical-rl;
font-size: 50px;
font-weight: bold;
}
<svg width="500" height="500">
<defs>
<linearGradient id="grad-md" x1="100%" y1="0%" x2="0%" y2="0%">
<stop offset="0%" style="stop-color:#374151; stop-opacity:1"></stop>
<stop offset="55%" style="stop-color:#374151; stop-opacity:1"></stop>
<stop offset="100%" style="stop-color:#fff; stop-opacity:0"></stop>
</linearGradient>
</defs>
<text x="50" y="50" fill="url(#grad-md)">测试文本123</text>
</svg>
As you can see, the initial few Chinese characters are not displaying correctly, and the direction of the gradient for Chinese text is incorrect.
2
Answers
There are two points you need to focus on achieve your result:
linear-gradient
to make it work vertically.writing-mode
directly to text.By default
text-origination
ismixed
, which applys differently for different languages. That causes the gradient calculation using different coordinating systems (according to Robert. This is a known bug on Chrome). You can force them to use eitherupright
orsideways
to uniform the calculation (but that means your Chinese will be sideways as well):However if you just want to apply some gradient to a text, a non-SVG solution might be a better choice: