1

My code contains a word or string that ends with Arabic ketter and then a number. But for some reasons, the number appear before the Arabic as if it's treated as an Arabic number even in the editor.

<!DOCTYPE html>
<html>
<body>
    <p>Englishالعربية 1English</p>
</body>

I can't even separate the arabic text because the word is "Englishالعربية" and not just Arabic. How can I make the number appear after arabic but not by actually writing it after English and before Arabic, because this would ruin the word itself for visualization.

I can't even show the code properly, because even the browser and the editor shows the number before the arabic text. But the steps to reproduce this problem is as follows:

  1. Write Englishالعربية English first.
  2. Put 1 just before the second E.

Then you will see that the 1 automatically moves somewhere else.

3
  • use separate containers to prevent misalignment. Commented Jan 29 at 14:31
  • jsfiddle.net/ahqLnmkp Commented Jan 29 at 14:56
  • @mrmcwolf Thanks, but I already said that Englishالعربية is a single word. I forgot to say it, but I am fetching these words from somewhere else. So, I can't break a word like this. Commented Jan 29 at 15:09

1 Answer 1

2

both the <p> and <span> tags now support the dir attribute (docs here), which is especially useful for mixed-direction content. You can specify two directions: ltr (left to right) and rtl (right to left).

In this case, I'd use this approach:

Wrap each word in a <span> and add the dir attribute

<!DOCTYPE html>
<html lang="en">
<body>
    <p>
        <span dir="ltr">English</span>
        <span dir="rtl">العربية</span>
        <span dir="ltr">1English</span>
    </p>
</body>
</html>

Hope this helps! If not, feel free to let me know in the comments.

Sign up to request clarification or add additional context in comments.

4 Comments

Both of them still make it look as if English was written first, then 1, then العربية and then another English. It doesn't look like English first, then العربية and then 1 and then another English.
Hi @RajinCoding2007, I check out my code, indeed I forgot to add in the first approach the "dir" attribute, now should work as expected.
@Issac-Blanco I said that I can't break the word Englishالعربية. And dir=rtl wasn't actually needed. I saw that when I wrote it like this: <span>Englishالعربية</span><span dir="ltr">1English</span>, it also worked. But for some reasons, replacing dir="ltr" with style="direction: ltr" doesn't work in both your code and <span>Englishالعربية</span><span dir="ltr">1English</span>. But using dir="ltr" did solve my problem. Thanks.
Oh ok, @RajinCoding2007, thanks for the feedback and happy to know that worked, have a great day :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.