Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force a piece of text to be 'direction ltr' inside a 'direction rtl' paragraph

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?

like image 273
Jonathan Avatar asked Dec 01 '10 15:12

Jonathan


People also ask

How do I change the direction of RTL?

By default, the text on the landing page is displayed in the left-to-right (LTR) order. This applies to both text created using the Text widget and user input in the form fields. You can change the text direction to RTL (right-to-left) by adding CSS code to the landing page.

How do I change the direction of RTL in HTML?

Setting up a right-to-left pageAdd dir="rtl" to the html tag any time the overall document direction is right-to-left (RTL). This sets the default base direction for the whole document. All block elements in the document will inherit this setting unless the direction is explicitly overridden.

Which property is used to set the direction of text as right to left?

The direction CSS property sets the direction of text, table columns, and horizontal overflow. Use rtl for languages written from right to left (like Hebrew or Arabic), and ltr for those written from left to right (like English and most other languages).


2 Answers

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

like image 115
Daniel Avatar answered Sep 22 '22 12:09

Daniel


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.

like image 41
Oded Avatar answered Sep 19 '22 12:09

Oded