3

Can I do that?

I mean if, for example, the contents of the <div> is Hebrew or Arabic, float the <div> right and give it a dir="rtl" attribute. And, if the contents of the <div> is English, float to the left and change the dir attribute to "ltr".

Ss that possible?

j0k
  • 22,600
  • 28
  • 79
  • 90
Pinokyo
  • 546
  • 1
  • 7
  • 15
  • 1
    How are you defining the language of each `div`? Can you show some HTML code? – Pekka May 15 '11 at 09:01
  • it's a like plugin from facebook the problem is that some people use the english version and some hebrew or arabic i just want to float the div accordingly is that possible? – Pinokyo May 15 '11 at 09:07
  • Have you tried it? i mean it's only a few lines of code. – PurplePilot May 15 '11 at 09:38
  • I don't think this is possible without pointing out the language of the `div` explicitly, e.g. using the `lang` attribute. The text orientation *should* work out automatically, but floating the `div` will need some attribute or class – Pekka May 15 '11 at 09:46
  • well Pekka if i will specify the language of the div can i make it dynamic? – Pinokyo May 15 '11 at 09:58
  • possible duplicate of [use text-align smartly (if english dir=ltr if arabic dir=rtl)](http://stackoverflow.com/questions/11787351/use-text-align-smartly-if-english-dir-ltr-if-arabic-dir-rtl) – NullPoiиteя Apr 26 '13 at 06:41

3 Answers3

2

If you don't know the language, you can use regular expression to find hebrew or arabic characters, and then set the direction accordingly.

Use regular expressions to find Hebrew: Javascript - how to find hebrew?

All unicode blocks, which you can use to edit the above solution to fit also Arabic: http://www.regular-expressions.info/unicode.html#block

Community
  • 1
  • 1
Gideon
  • 18,251
  • 5
  • 45
  • 64
0

well f the user has another language version you can check this (dont know where you save the user language, in a cookie?) fetch this with php or javascript and load the right stylesheet with the right rules

  • well how do you deliver the language versions for the page? does the user set the language in his account? so there is the languge that the user selected saved in a database? or do you use a (session) cookie for this? dont know how your website works. or you read the browser language with php? –  May 15 '11 at 10:03
  • the site is using php heavily but not that heavily i mean there is no sessions or cookies the div that i'm talking about is just a like plugin from facebook... i want to float it left or right if the language is hebrew then right if it's english then left.? is that possible? – Pinokyo May 15 '11 at 10:06
  • well but i dont know how you set the language for the user or the user can set it? more info? –  May 15 '11 at 10:07
0

You need to manually put dir attribute for for each div:

<div lang="ar" dir="rtl"><!-- some content here --></div>
<div lang="en" dir="ltr"><!-- some content here --></div>

This would automatically change flow. However, you might need to adjust certain elements depending on the language. You can do that by CSS lang pseudo-attribute:

p:lang(ar) { text-align: right; }
p:lang(en) { text-align: left; }

Of course you could possibly do that:

div:lang(en) { direction: ltr; }
div:lang(ar) { direction: rtl; }

This is unrecommended method. Since you need to put language somehow, you could also put dir attribute. If you do that from some programming language, directionality could usually be determined for given spoken language (Locale, Culture, whatever). But that would be another question.

Paweł Dyda
  • 18,366
  • 7
  • 57
  • 79