XML technologies / XML / XML in a Nutshell / Cascading Style Sheets (CSS) / The display property
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
Display is one of the most important CSS properties. It determines how an element is arranged on the page. There are 18 valid values, but the two main ones are inline and block. The display property can also create lists and tables or hide elements completely.
Inline elements
When display is set to inline, the default, the element appears at the next available position from left to right, like the words in this paragraph. The direction may differ for Hebrew, written right to left, or traditional Chinese, written top to bottom. Text wraps to the next line as needed, but no hard line breaks are inserted between inline elements. In the code examples Marjorie Anderson’s recipe for Southern Corn Bread and A CSS stylesheet for recipes the elements menge, schritt, person, stadt and staat were formatted inline. This did not need specifying explicitly because it is the default.
Block elements
Unlike inline elements, an element set to display: block is separated from its siblings, generally by a line break. In HTML paragraphs and headings, for example, are block elements. In the examples above, the elements gericht, anweisungen and geschichte are formatted with display: block.
CSS 2.1 adds an inline-block value that formats element content as a block element, but the element itself as an inline element. Usually this simply adds margins and padding around the content without line breaks before or after the element.
List items
An element whose display property is set to list-item is also formatted as a block, with a bullet inserted at its start. The properties list-style-type, list-style-image and list-style-position control the bullet’s character or image and the list’s indentation. For example, this rule formats the steps as a numbered list rather than a simple paragraph:
schritt {
display: list-item;
list-style-type: decimal;
list-style-position: inside
}Hidden elements
An element whose display property is set to none is omitted from the rendered document. It is invisible, occupies no space, and does not affect other elements’ placement. For example, this rule hides the element geschichte completely:
geschichte {display: none} Table elements
There are ten display values identifying elements as table components:
tableinline-tabletable-row-grouptable-header-grouptable-footer-grouptable-rowtable-column-grouptable-columntable-celltable-caption
These values have clear meanings by analogy with HTML 4.0 table tags. Use them consistently with each other and other document elements. For example, an element formatted as a table row (table-row element) should have a parent formatted as a table (table) and children formatted as table cells (table-cell). For example, these three rules format the ingredients as a simple table:
zutaten { display: table }
zutat { display: table-row }
menge, komponente { display: table-cell }
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de