为什么dir ="rtl"?更改订单,但只是有时? [英] Why does dir="rtl" change order, but only sometimes?

查看:105
本文介绍了为什么dir ="rtl"?更改订单,但只是有时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么

<input type="text" dir="rtl" value="08/15 word">

渲染到word 08/15而不是08/15 word?

为什么

<input type="text" dir="rtl" value="one word">

渲染到one word?

为什么在第一种情况下切换顺序,而在第二种情况下却不切换?

Why is the order switched in the first case but not in the second one?

https://jsfiddle.net/powtac/4aLn71mb/

推荐答案

dir=rtl给出了文本的基本方向.在该文本中,带有拉丁字母的单词仍将按从左到右的顺序书写,并且带有拉丁字母的多个单词(即英语的句子)也将按从左到右的顺序排列!

dir=rtl gives the base direction of the text. Within that text, words with Latin letters will still be written left-to-right and multiple words with Latin letters (i.e. English sentences) will be ordered left-to-right as well!

例如阿拉伯语,沿dir=ltr(默认)基本方向:它将始终从右到左书写,并且即使环境另有说明,多个阿拉伯语单词也将从右到左排序.

The same is true for e.g. Arabic in dir=ltr (default) base direction: it will be written right-to-left anyway, and multiple Arabic words will be ordered form right-to-left, even though the environment tells otherwise.

为此,浏览器(或通常的文本渲染器)使用Unicode bidi算法.该算法本身需要知道字符的方向性,这也是Unicode的一部分.拉丁字母和阿拉伯字母的方向性很强,而正常"数字的左右方向则较弱.

For that to work, the browser (or text renderer in general) uses the Unicode bidi algorithm. The algorithm by itself needs to know the directionality of the characters, which is part of Unicode as well. Latin and Arabic letters have a strong directionality, while the "normal" numbers have a weak left-to-right direction.

在弱和强之间进行了区分,因为在ltr和rtl语言中都使用数字.数字本身始终是从左到右书写的,但是如果被强壮的rtl单词包围,则将按从右至左的顺序对单词进行排序;如果被强壮的ltr单词包围,则将按从左至右的顺序对单词进行排序.

This distinction between weak and strong is made, because numbers are used in both ltr and rtl languages. The number itself is always written left-to-right, but it will be word-ordered right-to-left if surrounded by strong rtl words, and it will be word-ordered left-to-right if surrounded by strong ltr words.

如果数字不被强键入词包围,则使用基本方向.

If the number is not surrounded by strong typed words, the base direction is used.

您的ltr-"08/15"没有被ltr包围,因此它是从ltr单词"word"放置rtl(基本方向).

Your ltr-"08/15" is not surrounded by ltr, so it is put rtl (base direction) from ltr-word "word".

一个单词"是两个有方向性的单词,因此它们本身是ltr的布局,而这些单词也是ltr的布局.不管基本方向是什么.

"one word" are two strong directioned words, so they are layed out ltr themselves and the words layed out ltr as well. No matter what the base direction is.

尝试第一08/15秒",数字将被认为是更大的ltr句子的一部分,并列出了ltr.

Try "first 08/15 second" and the numbers will be considered part of a bigger ltr sentence and laid out ltr.

这篇关于为什么dir ="rtl"?更改订单,但只是有时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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