Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

styling bidirectional websites CSS best practice?

I am working on a website consists of four languages (Arabic, English, French and Spanish), (Arabic is a right-to-left language for people who don't know that).

Basically left-to-right (en, es and fr) sites will have the same layout/CSS.

in order to handle different arabic styles I am wondering between two methods:

1. specific language/direction class:

adding the following classes to html tag, and using one simple file to handle that

  • arabic <html class="ar rtl" dir="rtl">
  • english <html class="en ltr">
  • french <html class="fr ltr">
  • spanish <html class="sp ltr">

2. using separate files:

in this case I would use lets say a common.css file for all common things, and load a separate specific language/direction file (something like arabic.css or western.css)

What do you think the best option will be ?

Thanks

like image 740
Anas Nakawa Avatar asked Jun 28 '11 09:06

Anas Nakawa


People also ask

Is CSS bidirectional?

To produce the desired right-to-left or bidirectional effect, some people simply apply CSS to whatever general paragraph or inline elements surround the relevant text. However, styling applied by CSS is not permanent. It may be turned off, be overridden, go unrecognised, or be changed/replaced in different contexts.


2 Answers

Option #2 sounds like the more manageable solution. This way you can simply load the appropriate style sheet based on the language chosen. Since it sound like the text in your webpage updates based on the language selected (ie it is not physically written out twice) two separate style sheets will allow you to modify the layout without messing with the content in the html markup. So more information on how the languages are going to be switch might help you to get better answers.

like image 108
pat8719 Avatar answered Oct 12 '22 09:10

pat8719


I am not really sure why you need specific classes for Arabic texts. OK, you might want to modify fonts (as in font-family or font-size) but not much more than that. To switch directionality, you should use dir attribute (that is W3C recommendation).

As for styling elements, if you really need to modify styles for each element, you might want to use universal selector:

* { font-family: Verdana; }

For elements in given language (if you remember to use lang attribute), you can also use universal selector in conjunction with lang pseudo-selector (beware that some web browsers does not seem to support it, although it should be supported since CSS2):

*:lang(ar) { font-size: 14px; }
like image 22
Paweł Dyda Avatar answered Oct 12 '22 08:10

Paweł Dyda