Style maxHeightProperty

Style 对象参考手册Style Object

Definition and Usage

The maxHeight property sets or returns the maximum height of an element.

The maxHeight property only takes effect on block-level elements or elements with absolute/fixed positioning.

Note:An element's height can never be greater than the value specified by the maxHeight property.

Syntax

Set the maxHeight property:

Object.style.maxHeight="none|length|%|inherit"

Return the maxHeight property:

Object.style.maxHeight

Value Description
none Default. The element's height has no limit.
length Defines the maximum height using units such as px, cm, etc.
% Defines the maximum height as a percentage of the parent element.
inherit The value of the maxHeight property is inherited from the parent element.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the maxHeight property.

Note:IE7 and earlier versions do not support the "inherit" value. IE8 only supports "inherit" if a !DOCTYPE is specified. IE9 supports "inherit".


Example

Example

Set the maximum height of an element:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function displayResult(){
    document.getElementById("p1").style.maxHeight="15px";
}
</script>
</head>
<body>

<p style="background:red;" id="p1">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</p>
<input type="button" onclick="displayResult()" value="Set the maximum height of the element">

</body>
</html>

Try it yourself »


Style 对象参考手册Style Object Other Extensions