XML technologies / CSS / Advanced websites with CSS / CSS property reference / max-width, min-width

(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)

The properties max-width and min-width describe the maximum or minimum width an element may occupy. The browser first calculates the element’s width normally, then applies the limit.

When using max-width, set the property overflow to hidden; otherwise, the element’s contents may exceed the specified width.

Inherited: no

See also: width, max-height, min-height

Values

A CSS measurement, a percentage of the parent element’s content height, or, for max-width, the constant none.

Default value:

  • max-width: none

  • min-width: 0

Compatibility

CSS version: 2

Works only in Netscape 6, Opera 7 and later, and Mozilla.

Example

The following rule restricts the element with the ID oberesmenue to a width between 200 and 1000 pixels and displays a scrollbar if its contents exceed the element’s maximum width:

#oberesmenue{
 min-width: 200px;
 max-width: 1000px;
 overflow: auto;
}

  

  

 

 

 

back to top