XML technologies / CSS / Advanced websites with CSS / CSS property reference / width
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
The property width describes the width of a block element or an element replaced from an external source. (A replaced element’s appearance is determined by an external source, for example images through elements img, plugins through elements object, and text input fields through elements input and select. Another type of replaced element is content inserted inline by CSS pseudo-elements.) The width excludes padding, border and margin.
If a block element’s content is wider than its assigned value of width, the result depends on the CSS property overflow.
Inherited: no
See also: height, max-width, min-width, overflow, text-overflow
Values
An absolute CSS measurement, a percentage of the parent element’s width, or the constant auto.
Default value: auto
Compatibility
CSS version: 1
Works with limitations in all CSS-capable browsers. Fully supported in current CSS2-capable browsers (Netscape 6, Opera 7, Mozilla and Internet Explorer 5 for Macintosh).
Internet Explorer for Windows, up to version 6.0, incorrectly includes padding, border and margin in width calculations. Only version 6.0’s Standards-Compliant Mode avoids the error. Other versions require a separate stylesheet or acceptance of a box reduced by margins and borders.
Internet Explorer 4 supports this property only for certain block elements, such as div.
Netscape 4 supports this property only for images and elements positioned with absolute.
Example
The following style rule gives paragraphs with ID textbaustein a fixed width of 100 pixels:
#textbaustein p {
width: 100px;
}
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