当文本行以数字开头时,在RTL模式下数字将显示在右侧.为什么? [英] When line of text starts with a number, a number shows up on right in RTL mode. Why?

查看:79
本文介绍了当文本行以数字开头时,在RTL模式下数字将显示在右侧.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将以下html代码段粘贴到浏览器中的新标签页中:

Try pasting the following html snippet into a new tab in your browser:

data:text/html,<html dir=rtl>5 little ducks went out to play.

文本输出右对齐,如下所示:

The text outputs, right aligned, like so:

.小鸭子出去玩5

.little ducks went out to play 5

为什么5被移到行尾?

如果将5更改为非数字值,例如5a,则文本将按我期望的那样显示:

If I change the 5 to a non-numeric value, such as 5a, the text displays as I would expect:

.5外出玩耍时有一只小鸭子

.5a little ducks when out to play

我已经在Ubuntu上的Chrome和Firefox中复制了它,因此我假设它不是浏览器错误.

I've reproduced it in both Chrome and Firefox on Ubuntu, so I am assuming that it is not a browser bug.

我的语言环境是美国,并且我将编码设置为UTF-8.

My locale is en-US and I have the encoding set to UTF-8.

更多示例使这看起来更陌生.如果句子以单词开头,那么事情也会按预期出现:

A few more examples make this seem even stranger. If the sentence starts with a word, things also appear as expected:

.5只小鸭子出去玩

我猜想接下来也要问类似的问题.

I suppose a similar question follows as to why the period is also being moved.

最后,如果我在CSS中抛出bidi-override,则所有内容都会颠倒过来,但是顺序正确:

Lastly, if I throw a bidi-override in the css, everything appears reversed but otherwise in the correct order:

data:text/html,<html dir=rtl><div style="unicode-bidi: bidi-override;">5 little ducks went out to play.

.yalp ot tuo tnew skcud elttil 5

.yalp ot tuo tnew skcud elttil 5

推荐答案

dir属性设置定向中性文本的方向性以及整体布局方向(例如,表格列的布局顺序).拉丁字母在方向上不是中立的.他们具有强烈的左右方向性.

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.

就方向性而言,内容5 little ducks went out to play.由三部分组成:字符5,带空格的拉丁字母字符串和字符..当从右到左的方向性应用于此时,您将按从右到左的顺序获得这些部分.

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.

当您将5替换为5a时,方向中性的5受左至右字符a的控制,因此字符串5a被视为属于左序列.正确的字符.

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.

当您拥有The 5 little时,中性5再次加入到从左到右的帮派中,因为它位于两个强烈的从左到右的琴弦之间.

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.

所有这些都在Unicode BiDi规则中进行了描述.

This is all described in Unicode BiDi rules.

在CSS中设置unicode-bidi: bidi-override或等效地在HTML中使用<bdo>元素时,将覆盖整个Unicode BiDi算法.与字母关联的所有固有方向性都将被忽略.无论如何,字符都严格从左到右或从右到左进行布局.

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.

道德是,通常只应为习惯上从右到左书写的文本设置方向性,例如希伯来语,阿拉伯语或波斯语.如果您仅出于随意布局目的而使用方向性,请当心;它可能会咬你.而且,如果您混合使用了从左到右或从右到左的文本,请使用嵌入(unicode-bidi: embed)而不是蛮力的方向性替代.

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.

这篇关于当文本行以数字开头时,在RTL模式下数字将显示在右侧.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆