如果用户可以使用rtl或ltr语言,如何自动更改输入字段的CSS方向属性 [英] How to Change CSS direction property of the input field automaticly if the user can use an language rtl or ltr

查看:286
本文介绍了如果用户可以使用rtl或ltr语言,如何自动更改输入字段的CSS方向属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:如果我使用阿拉伯语言,文本字段的方向将是rtl,如果我想写一个新文本,我切换到英语语言文本字段内的方向(`text-align:left)将是ltr自动

Example: if I use arabic language the text field direction will be rtl and if I want to write a new text and I switch to the English language the direction inside the text field (`text-align: left) will be ltr automatically

推荐答案

您可以使用全局HTML5属性 dir auto 如下:

You could use the global HTML5 attribute dir with a value of auto here, like so:

<input type="text" dir="auto" />

根据规范:


auto 关键字,它映射到自动状态表示元素的
内容是显式嵌入的文本,但
方向是使用
元素(如下所述)的内容以编程方式确定。

The auto keyword, which maps to the auto state Indicates that the contents of the element are explicitly embedded text, but that the direction is to be determined programmatically using the contents of the element (as described below).

注意:启发式通过这种状态是非常粗糙的(它只是看着
第一个字符与强方向性,在方式类似于
的双向算法中的段级确定)。
当文本的
方向是真正未知的并且没有更好的服务器端
启发式可以应用时,作者最好只使用这个值作为最后的手段。

Note: The heuristic used by this state is very crude (it just looks at the first character with a strong directionality, in a manner analogous to the Paragraph Level determination in the bidirectional algorithm). Authors are urged to only use this value as a last resort when the direction of the text is truly unknown and no better server-side heuristic can be applied.

http://www.w3.org/TR /html5/elements.html#the-dir-attribute

正如此报价所示,最好找到在服务器端使用哪个方向,但如果您无法知道它,您可以使用此方法。

As this quote suggests, it would be better to find out on the server side which direction should be used, but you can use this if you have no way of knowing it.

这篇关于如果用户可以使用rtl或ltr语言,如何自动更改输入字段的CSS方向属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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