5

When I am trying to add text to the div (div has dir = RTL), it moves the content to the right side. However, it keeps the special characters like . / + to the left side, if they are the last character for the sentence.

Example:

<dir dir="RTL">Hello There!</dir>

Out put will be: !Hello There

Could any one help with this?

peterh
  • 11,875
  • 18
  • 85
  • 108
narsi
  • 73
  • 1
  • 6
  • 1
    Why are you using `dir='rtl'` for content that is not in a right-to-left language? If you just want to align text to the right, use `text-align: right` in CSS (or `align=right` in HTML for the elements that allow it). – Jukka K. Korpela Jul 17 '14 at 10:23
  • 1
    I also want this because I want text aligned on the left, but when it overflows its box, I want the ellipsis (using `text-overflow: ellipsis`) to appear on the left, not the right as usual. `dir='rtl'` works, except for the weird symbol displacement – poshest Sep 02 '19 at 15:35

1 Answers1

8

You need to use the <bdi> (bi-directional text) tag to wrap your text, see this article

<div dir="RTL">
   <bdi>
      Hello There!
   </bdi>
</div>

More on bdi from MDN

Unfortunately this is only supported in Chrome and FireFox.

As Jukka mentions, this will effectively accomplish the same as right-aligning your text, in which case you should be doing that.

See here for a list of examples

Community
  • 1
  • 1
SW4
  • 69,876
  • 20
  • 132
  • 137
  • 1
    `` is just bidi isolate. The ``, bidi override, has much better support and works if you use `...`. But it sounds so... odd to ask for RTL and yet want LTR, which is what the question seems to be asking. – Jukka K. Korpela Jul 17 '14 at 10:26
  • @JukkaK.Korpela - that's a better answer +1 – SW4 Jul 17 '14 at 10:28
  • @JukkaK.Korpela The reason im asking for RTL and want LTR is that I want some thing like google's "Scientific Claculator" display.. it goes from right to left ....I tried many methods but they are not working for me. So I went with this route... – narsi Jul 17 '14 at 10:34
  • @SW4 If I add this bdo or bdi, it is just going LTR again as you said. But I want it to be RTL and have punctuation to the right too... Is there any way? – narsi Jul 17 '14 at 10:42
  • @narsi, you should edit the question to explain what you are really doing. Show a mini-example with just a few items. You probably need to set RTL direction for a list element and LTR direction for elements inside it, or something like that. – Jukka K. Korpela Jul 17 '14 at 12:43
  • @narsi adding ‎ at the end worked for me: https://stackoverflow.com/a/42551367/1555348 – domsch Jun 09 '20 at 09:15