8

Now I have a string like (in ltr)

Hebrew text(3)

and when I use dir="rtl" or direction:rtl to redirect the string it actually goes:

מחיר אחד(3)

(actually i entered Hebrew charactor(3) just now it automaticlly became like above↑)

is there any way to make it like

(3)Hebrew text

(using html or css)

Greg
  • 18,111
  • 5
  • 46
  • 68
sleepholic
  • 83
  • 1
  • 4

3 Answers3

11

You don't need to wrap the bracketed text in a separate span.

Rather, to fix this problem add a RLM control character (‏) after the closing bracket. The RLM character acts as another Hebrew/Arabic character and so the bracket ( which is a weak character) changes its direction and moves to its correct place.

Like so:

<div>מחיר אחד(3)&rlm;</div>

NB: If you set the attribute dir="rtl" on the element - then even the RLM control character is unnecessary.

Like so:

<div dir="rtl">מחיר אחד(3)</div>

CODEPEN (jsFiddle down by me)

This microsoft doc explains the RLM control character along with other similar control characters.

Danield
  • 121,619
  • 37
  • 226
  • 255
  • I found my example in the article not very appropriate~you r right in your second line of codes,when i use dir='rtl' and thansk to browser everything goes well(i remember when i set up this question it messed up...is this my illusion or chrome updated..?) – sleepholic Jan 23 '14 at 08:10
  • 1
    anyway my problem has been solved.But i think out a new condition that when i use a hebrew phrase in english(ltr) or an english phrase in hebrew(rtl) with brackets,it will also messes up.In the case if we dont wanna waste a span to wrap and style the specific language phrase we can use `‏` or `‎`. – sleepholic Jan 23 '14 at 08:24
6

(updated: thank you rob for clarifying your comment)

this is a little less invasive solution (result in jsFiddle):

<span lang="he" dir="rtl">מחיר אחד<span>(3)</span></span>

It seems the last parentheses is concidered as punctuation and thus treated differently. This article gave me some clarity:

... Note that unlike align="right", the punctuation will also relocated... See Sample RTL Document

In the sample document the same relocation of the last parentheses also occurs within the subtitle "Bidirectional Override (BDO)".

*checked the jsfiddle solution in latest chrome/ff/safari/ie

Jaak Kütt
  • 2,566
  • 4
  • 31
  • 39
  • Are you aware if the solution you supply is a known bug you are working around or your solution is the correct way to deal with the expected browser behaviour? What browsers did you test your solution in ? – rob Sep 30 '13 at 10:43
  • 1
    Since I am not familiar with rlt languages and thus with their browser specifics I can't be 100% sure if my solution is the absolute correct way for dealing with the given situation but if the parentheses are concidered as punctuation and as such a subject for relocation, a span wrapper seems to cancel that behaviour. – Jaak Kütt Oct 01 '13 at 20:16
0

one of the solutions is to add **&#x200e;** after the bracket

thanks to @freeworlder for the solution on brackets displays wrongly for right to left display style

even you can use other char, follow this link http://www.codetable.net/hex/200e