29

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?

Flimm
  • 136,138
  • 45
  • 251
  • 267
Jonathan
  • 8,676
  • 20
  • 71
  • 101
  • 2
    RTL algorithms normally take numbers into account, so you don't need to do anything for numbers to be rendered correctly, regardless of `LTR` or `RTL` of the container. Are you actually seeing this issue or simply trying to preempt? – Oded Dec 01 '10 at 15:04
  • 2
    @Oded: I'm seeing it. I think because of the '+' and '-' between numbers its just confusing the algorithm... – Jonathan Dec 01 '10 at 15:05
  • In Arabic at least, the + sign should go to the left of a phone number, just like it does in English. Type out the phone number just like you would in English, first type the `+` character, then the first number from the left, then the second number from the left, and so on. You may be trying to fix something which isn't actually a problem. – Flimm Dec 09 '17 at 11:19

4 Answers4

36

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

Daniel
  • 2,331
  • 3
  • 26
  • 35
  • 1
    `Because HTML UAs can turn off CSS styling, we recommend HTML authors to use the HTML dir attribute and element to ensure correct bidirectional layout in the absence of a style sheet. Authors should not use direction in HTML documents.` Source: http://www.w3.org/TR/css-writing-modes-3/#direction – Dan Loewenherz Apr 22 '16 at 16:29
27

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">&#x200F;+44-123-321</span> for some help</p>

See this SO answer for more details.

Flimm
  • 136,138
  • 45
  • 251
  • 267
Oded
  • 489,969
  • 99
  • 883
  • 1,009
15

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 &#x200E; in your HTML is as bad as using dir='ltr' attribute.

Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
0

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

<span dir="ltr">&lrm;א + ב = ג</span>

You can force it with &#x202D; (LEFT-TO-RIGHT OVERRIDE)

<span>&#x202D;א + ב = ג</span>

or by using css unicode-bidi: bidi-override

<span style="unicode-bidi: bidi-override;">א + ב = ג</span>
Arik
  • 5,266
  • 1
  • 27
  • 26