FortySeven Media

Kick Awesome Web Design, Graphic Design & Media Creation

Styling Right-To-Left Text with CSS on a Multi-Lingual Site

Friday, March 06, 2009 ~ 10:45 am

We recently had the pleasure of working with CD Baby creator Derek Sivers on a new project called MusicThoughts. It's a great collection of quotes from musicians on everything from the music industry to life in general. In short, pretty kick-awesome! Go check it out already!

This was a challenging project from start to finish. First of all, we couldn't modify the HTML at all, only the CSS. And second was the support for multiple languages. 10 to be exact! This had several ramifications:

Music Thoughts comparison

And it's the last point I wanted to explore a bit more. You see, for languages that read from right to left there's a dir="rtl" attribute that we can tie into with CSS so we can target it and style appropriately. Mr. Sivers put his on the html element:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ar" dir="rtl">

So for instance, the navigation got all messed up when it was text-aligned right. All we have to do is target it with CSS and make minor modifications:

html[dir="rtl"] #navigation {
float: right;
display: inline;
margin-left: 0px;
margin-right: 360px;
}

And that's it! Rinse and repeat for the affected areas. Believe it or not, this targeting seems to be supported by all the major browsers (unheard of, I know!) so try it out on your next multi-lingual site and see how awesome it is.

  • Social Web
  • E-mail

Your Email:*  

Your Name:*

               To:*

Submit the word you see below*

Posted by (JavaScript must be enabled to view this email address) in Design ~ Tutorials ~ (4) Comments ~

Really interesting post guys. I am in the early stages of a project that could require a multi-lingual approach, the technique you’ve outlined will definately come in handy.

Just one question for you though, i noticed the following code in the head

xml:lang=“ar” 

Does that automatically change the language of a page or did you have to translate each page manually?

Apologies if thats a stupid question but i am intrigued, thanks

@David - Not a stupid question at all! I believe Derek is paying translators for each quote actually, but he’s using some kind of system to switch between languages (not sure what it is as we never got access to the server for this project). So basically the xml language is switching through that system. I’ll check with him and see what he’s using.

Hey David, just talked to Derek. He built his own translating system, but he said it’s pretty similar to others out there. You can catch him at http://sivers.org/ to find out more.

Nice trick indeed.  But it doesn’t work in Internet Explorer 6 for those of us who still want to support that piece of crap:
http://www.quirksmode.org/css/contents.html
http://www.quirksmode.org/css/selector_attribute.html

Congrats for the very good idea.

Leave Your Thoughts Behind

Name*

Email*

Website

Smileys

  Remember my personal information

  Notify me of follow-up comments?

Submit the word you see below*

Live Preview

 
Separator
Design Hope for Startups 2009
Stuff we Love

BestChristianDesign is helping give churches inspiration for their next project. Good call, guys.

Seth Godin reminds us to enjoy and take advantage of the uphills.

Stop announcing your new project. Just do it.

Rock and Roll people, Rock and Roll.

To all you staff designers out there, here’s a link for you. (via @ryanlascano)

Fascinating look into the music business.

Derek Sivers posts some great advice about balancing your life.

archives

Rad Deals
Troy McNeil - Things I said

Troy McNeil
Things I Said

Buy in iTunes
Tweets
profile image

Late night run to the grocery. Not enough hours in the day!

Tue 11:11 | Follow
profile image

Javascript makes Instant Messanger sad. http://twitpic.com/17lqzl #javascript #codegonewrong

Tue 4:50 | Follow
Tweets
Recommended

ExpressionEngine

Basecamp