Export (0) Print
Expand All

max-width

Sets the maximum width for an element.

{ max-width: sMaxWidth }

sMaxWidth

Variant that specifies or receives the maximum width for an element:

length

Floating-point number followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px).

For more information about the supported length units, see Length units reference.

percentage

Integer that is followed by a percent sign (%) and that specifies a percentage of the containing block width to use as the maximum width of the element. If the width of the containing block is not explicitly set, the element has no maximum width and the max-width property is interpreted as 0%. For more information about containing blocks and how their widths are computed, see the Cascading Style Sheets (CSS), Level 2, Revision 1 (CSS2.1) specification.

The property has no default value. It is not inherited.

The min-width and max-width attributes apply to floating and absolutely positioned block level elements, inline-block elements, and also some intrinsic controls. They do not apply to non-replaced inline elements, such as table rows and row/column groups. (A "replaced" element has intrinsic dimensions, such as an IMG element or a TEXTAREA element.)

This property is enabled only under the strict !DOCTYPE.

The following example shows how to constrain the width of a DIV element by using min-width and max-width attributes. The example can be viewed only with Internet Explorer 7 or a later version:

<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 Strict//EN">
<html>
<head><style>
.width {
    width:50%;
    min-width:200px;
    max-width:400px;
    background:#eee;
}
.content {
    border :1px solid #c00;
    padding:5px;
}
</style>
</head>
<body>
<div class="width">
<div class="content">
        <h2>{min-width:200px; max-width:400px}</h2>
        <p>This div also has a width of 50%. Resize the window
         to grow and shrink the div from max to min width.<br/><br/>
         The outer div controls the width of the inner "content" div.
         Note that the div height increases to accomodate the flow of text.</p>
</div>
</div>
</body>
</html>

A, ABBR, ACRONYM, ADDRESS, APPLET, B, BDO, BIG, BLOCKQUOTE, BUTTON, CAPTION, CENTER, CITE, CODE, CUSTOM, DD, DEL, DFN, DIV, DL, DT, EM, FIELDSET, FONT, FORM, HN, HR, I, IMG, INPUT TYPE=BUTTON, INPUT TYPE=CHECKBOX, INPUT TYPE=FILE, INPUT TYPE=IMAGE, INPUT TYPE=PASSWORD, INPUT TYPE=RADIO, INPUT TYPE=RESET, INPUT TYPE=SUBMIT, INPUT TYPE=TEXT, INS, LI, OL, OPTION, P, Q, RT, RUBY, S, SELECT, SPAN, SUB, TT, U, UL, VAR, XMP

Community Additions

ADD
Show:
© 2014 Microsoft