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;
}

  

 

 

 

back to top