如何强制一段文本为“方向ltr”在“方向 rtl”内;段落

发布于 2024-10-05 23:29:49 字数 849 浏览 0 评论 0原文

因此,电话号码始终是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乞讨 2024-10-12 23:29:49

尝试添加 #phone {direction:ltr;显示:内联块}

Try adding #phone {direction:ltr; display:inline-block}

献世佛 2024-10-12 23:29:49

您可以在 + 符号之前使用 unicode 方向性标记字符来为算法提供所需的提示。

这些是:

LTR: 0x200E
RTL: 0x200F

所以:

<p id="text">Please call to <span id="phone">‏+44-123-321</span> for some help</p>

有关更多详细信息,请参阅答案。

You can use a unicode directionality marker character just before the + sign to give the algorithm the hint it needs.

These are:

LTR: 0x200E
RTL: 0x200F

So:

<p id="text">Please call to <span id="phone">‏+44-123-321</span> for some help</p>

See this SO answer for more details.

自此以后,行同陌路 2024-10-12 23:29:49

另一种选择是在内联元素中使用 dir='ltr' 属性:

<p id="text">Please call to <span dir='ltr'>+44-123-321</span> for some help</p>

请注意,在 HTML 中包含 与使用 < 一样糟糕。 code>dir='ltr' 属性。

Another option could be to use dir='ltr' attribute, in your inline element:

<p id="text">Please call to <span dir='ltr'>+44-123-321</span> for some help</p>

Please note that including in your HTML is as bad as using dir='ltr' attribute.

爱要勇敢去追 2024-10-12 23:29:49

如果第一个字符是 LTR 字符,建议的解决方案将不起作用。

<span dir="ltr">‎א + ב = ג</span>

您可以使用 强制执行(从左到右覆盖

<span>‭א + ב = ג</span>

或者使用 css unicode-bidi: bidi-override

<span style="unicode-bidi: bidi-override;">א + ב = ג</span>

The suggested solutions won't work if the first character is an LTR character.

<span dir="ltr">‎א + ב = ג</span>

You can force it with (LEFT-TO-RIGHT OVERRIDE)

<span>‭א + ב = ג</span>

or by using css unicode-bidi: bidi-override

<span style="unicode-bidi: bidi-override;">א + ב = ג</span>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文