Style maxWidth attribute
- Forrige side maxHeight
- Næste side minHeight
- Gå tilbage et niveau HTML DOM Style Object
Definition and Usage
maxWidth
Sets or returns the maximum width of an element.
maxWidth
This attribute is only valid for block-level elements or elements with absolute or fixed positioning.
Note:The width of the element can never be greater than maxWidth
the value specified by the attribute.
Tip:To set or return the minimum width of an element, use minWidth property.
See also:
CSS Tutorial:CSS Dimension
CSS Reference Manual:max-width property
Example
Example 1
Set the maximum width of the <div> element:
document.getElementById("myDiv").style.maxWidth = "100px";
Example 2
Return the maximum width of the <div> element:
alert(document.getElementById("myDiv").style.maxWidth);
Syntax
Return maxWidth property:
object.style.maxWidth
Set maxWidth property:
object.style.maxWidth = "none|length|%|initial|inherit"
Attribute value
Value | Description |
---|---|
none | The width of the element is not restricted. Default. |
length | Define the maximum width in length units. |
% | Define the maximum width in percentage of the parent element. |
initial | Set this property to its default value. See initial. |
inherit | Inherit this property from its parent element. See inherit. |
Technical details
Default value: | None |
---|---|
Return value: | A string that represents the maximum width of an element. |
CSS version: | CSS2 |
Browser understøttelse
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Forrige side maxHeight
- Næste side minHeight
- Gå tilbage et niveau HTML DOM Style Object