html 按语言方向? (如果英语 dir=ltr 如果阿拉伯语 dir=rtl)
我可以这样做吗?
我的意思是,例如,如果
的内容是希伯来语或阿拉伯语,则将
向右浮动并为其指定 dir= “rtl”属性。并且,如果
的内容是英文,则向左浮动并将 dir
属性更改为 "ltr"
。
这可能吗?
Can I do that?
I mean if, for example, the contents of the <div>
is Hebrew or Arabic, float the <div>
right and give it a dir="rtl"
attribute. And, if the contents of the <div>
is English, float to the left and change the dir
attribute to "ltr"
.
Ss that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不懂该语言,可以使用正则表达式查找希伯来语或阿拉伯语字符,然后相应地设置方向。
使用正则表达式查找希伯来语:
Javascript - 如何查找希伯来语?
所有 unicode 块,您可以使用它们来编辑上述解决方案也适用于阿拉伯语:
http://www.regular-expressions.info/unicode.html#block
If you don't know the language, you can use regular expression to find hebrew or arabic characters, and then set the direction accordingly.
Use regular expressions to find Hebrew:
Javascript - how to find hebrew?
All unicode blocks, which you can use to edit the above solution to fit also Arabic:
http://www.regular-expressions.info/unicode.html#block
如果用户有另一种语言版本,你可以检查这个(不知道你在 cookie 中保存用户语言的位置?)使用 php 或 javascript 获取它并使用正确的规则加载正确的样式表
well f the user has another language version you can check this (dont know where you save the user language, in a cookie?) fetch this with php or javascript and load the right stylesheet with the right rules
您需要手动为每个 div 添加 dir 属性:
这会自动更改流程。但是,您可能需要根据语言调整某些元素。你可以通过CSS lang伪属性来做到这一点:
当然你可以这样做:
这是不推荐的方法。由于您需要以某种方式放置语言,因此您也可以放置 dir 属性。如果您使用某种编程语言执行此操作,通常可以确定给定口语(区域设置、文化等)的方向性。但这将是另一个问题。
You need to manually put dir attribute for for each div:
This would automatically change flow. However, you might need to adjust certain elements depending on the language. You can do that by CSS lang pseudo-attribute:
Of course you could possibly do that:
This is unrecommended method. Since you need to put language somehow, you could also put dir attribute. If you do that from some programming language, directionality could usually be determined for given spoken language (Locale, Culture, whatever). But that would be another question.