When line of text starts with a number, a number shows up on right in RTL mode. Why?

偶尔善良 提交于 2019-12-06 04:12:38
Jukka K. Korpela

The dir attribute sets the directionality of directionally neutral text, as well as overall layout direction (e.g., the layout order of table columns). Latin letters are not directionally neutral; they have strong left-to-right directionality.

The content 5 little ducks went out to play. consists of three parts, as far as directionality is considered: the character 5, the string of Latin letters with spaces, and the character .. When right-to-left directionality is applied to this, you get these parts in order, from right to left.

When you replace 5 by 5a, the directionally neutral 5 gets governed by the left-to-right characeter a, so the string 5a is treated as belonging to the sequence of left-to-right characters.

When you have The 5 little, the neutral 5 again gets joined into the left-to-right gang, because it is between two strongly left-to-right strings.

This is all described in Unicode BiDi rules.

When you set unicode-bidi: bidi-override in CSS or, equivalently, use the <bdo> element in HTML, you override the entire Unicode BiDi algorithm. All of the inherent directionality associated with letters gets ignored. Characters are laid out strictly left to right or right to left, no matter what.

Locales and encodings have nothing to do with this.

The moral is that you should normally set directionality only for texts that are conventionally written right to left, such as Hebrew, Arabic, or Persian. If you use directionality just for casual layout purposes, take care; it may bite you. And if you have mixed left-to-right or right-to-left texts, use embedding (unicode-bidi: embed) rather than brute-force directionality override.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!