如何强制一段文本为“方向ltr”在“方向 rtl”内;段落
因此,电话号码始终是ltr(从左到右)。
在多语言网站上工作,我需要在具有方向 rtl 的文本段落中插入一个电话号码(带有“+”前缀和用“-”分隔的数字)(当然对于相关语言)
所以我有这样的内容:
.ltr #test {direction:ltr}
.rtl #test {direction:rtl}
#phone {direction:ltr}
<div class="ltr"><p id="test">Please call to <span id="phone">+44-123-321</span> for some help.</p></div>
<div class="rtl"><p id="test">Please call to <span id="phone">+44-123-321</span> for some help.</p></div>
当然,这不起作用,因为“direction
”仅适用于块元素,而“span
”是内联元素。我需要将电话号码放在段落内,这样我就无法将 'span
' 更改为 'display:inline
'
我说清楚了吗?
如何让它发挥作用?
So, phone numbers are always ltr (left to right).
Working on a multilingual website I need to insert a phone number (with a '+' prefix and numbers separated by '-') inside a text paragraph that has direction rtl (for relevant languages of course)
So I have something like this:
.ltr #test {direction:ltr}
.rtl #test {direction:rtl}
#phone {direction:ltr}
<div class="ltr"><p id="test">Please call to <span id="phone">+44-123-321</span> for some help.</p></div>
<div class="rtl"><p id="test">Please call to <span id="phone">+44-123-321</span> for some help.</p></div>
Of course this is not working because 'direction
' only works for block elements and 'span
' is an inline element. I need the phone number to be inside the paragraph so I can't change 'span
' to 'display:inline
'
I'm being clear?
How to make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试添加
#phone {direction:ltr;显示:内联块}
Try adding
#phone {direction:ltr; display:inline-block}
您可以在
+
符号之前使用 unicode 方向性标记字符来为算法提供所需的提示。这些是:
所以:
有关更多详细信息,请参阅此答案。
You can use a unicode directionality marker character just before the
+
sign to give the algorithm the hint it needs.These are:
So:
See this SO answer for more details.
另一种选择是在内联元素中使用
dir='ltr'
属性:请注意,在 HTML 中包含
与使用 < 一样糟糕。 code>dir='ltr' 属性。Another option could be to use
dir='ltr'
attribute, in your inline element:Please note that including
in your HTML is as bad as usingdir='ltr'
attribute.如果第一个字符是 LTR 字符,建议的解决方案将不起作用。
您可以使用
强制执行(从左到右覆盖)或者使用 css
unicode-bidi: bidi-override
The suggested solutions won't work if the first character is an LTR character.
You can force it with
(LEFT-TO-RIGHT OVERRIDE)or by using css
unicode-bidi: bidi-override