XML technologies / CSS / Advanced websites with CSS / CSS property reference / direction
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
Most Western languages are written and read from left to right, while many Eastern languages run from right to left. The Unicode standard allows text mixing both directions to appear in one document. Special characters, such as currencies and other units of measurement, are also defined in Unicode.
The following text sketches a mixture of English and Hebrew. Words in the left-to-right language appear in lowercase, while words in the right-to-left language appear in uppercase:
englisch1 HEBRAEISCH1 englisch2 HEBRAEISCH2 englisch3
Now expand the example into an HTML fragment:
<p>englisch1 <q>HEBRAEISCH1 englisch2 HEBRAEISCH2</q> englisch3</p>The text beginning with HEBRAEISCH1 and ending with HEBRAEISCH2 should therefore appear as a quotation. The result should look like this: “englisch1 2HCSIEARBEH englisch2 1HCSIEARBEH englisch3”.
To represent this change of text direction on a web page, HTML 4.0 (or XHTML 1.0) provides the attribute dir and the element bdo. Our fragment should therefore look like this:
<p>englisch1 <q lang="he" dir="rtl">HEBRAEISCH1 englisch2 HEBRAEISCH2</q> englisch3</p>The attribute dir of q specifies the display direction, in this case “right-to-left”. The attribute lang has no visible effect. For a complete description of languages and displaying multilingual text, see section 8 of the HTML 4.0 standard.
The CSS property direction, combined with the property declaration unicode-bidi: embed, serves the same purpose as the HTML attribute dir. Using direction with the declaration unicode-bidi: bidi-override has the same effect as the HTML element bdo.
In a simple case like this, stick with the HTML attribute. The CSS properties direction and unicode-bidi are intended primarily for formatting XML documents that cannot benefit from bidirectional capabilities like HTML4. Because this book focuses on creating pages for the web, I refer you to the CSS2 standard for further information about these properties.
Inherited: yes
See also: unicode-bidi
Values
ltr or rtl.
Default value: ltr
Compatibility
CSS version: 2
Not supported by any current browser.
Example
The following style rule sets the writing direction of an XML element named hebraeisch to rtl. The property unicode-bidi ensures that all contained elements are grouped in the correct direction, even when the element hebraeisch is displayed as an inline element.
hebraeisch {
direction: rtl;
unicode-bidi: embed;
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg