XML technologies / CSS / Advanced websites with CSS / CSS property reference / unicode-bidi
(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 example sketches text mixing English and Hebrew. Words in the left-to-right language appear in lowercase, and words in the right-to-left language 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 expected result is: »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 primarily intended for formatting XML documents that cannot benefit from bidirectional capabilities like HTML 4.0. Since this book focuses on web pages, I refer you to the CSS2 standard for further information about these properties.
Inherited: no
See also: direction
Values
The property unicode-bidi accepts the following constants:
normal: The element’s content is displayed as LTR (left-to-right) or RTL (right-to-left) text according to its writing direction; settings fordirectionare ignored.embed: The element groups content with different writing directions and uses the direction specified bydirectionfor these groups, corresponding to the HTML attributedir.bidi-override: All content is displayed in the direction specified bydirectionregardless of its actual writing direction, corresponding to the HTML elementbdo.
Default value: normal
Compatibility
CSS version: 2
Not supported by any current browser.
Example
The following rule sets the writing direction of an XML element named hebraeisch to rtl. The property unicode-bidi ensures that all content within hebraeisch appears in the direction specified by direction even if this contradicts its original writing direction.
hebraeisch {
direction: rtl;
unicode-bidi: bidi-override;
}
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