Style maxHeight 属性

Style 对象参考手册 Style 对象

定义和用法

maxHeight 属性设置或返回元素的最大高度。

maxHeight 属性只在块级元素或绝对/固定位置的元素发挥作用。

注意:一个元素的高度永远不能大于 maxHeight 属性规定的值。

语法

设置 maxHeight 属性:

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

返回 maxHeight 属性:

Object.style.maxHeight

描述
none 默认。元素的高度没有限制。
length 使用 px、cm 等单位定义最大高度。
% 定义最大高度为父元素的百分比。
inherit maxHeight 属性的值从父元素继承。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 maxHeight 属性。

注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有规定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。


实例

实例

设置元素的最大高度:

<html>
<head>
<script>
function displayResult()
{
document.getElementById("p1").style.maxHeight="15px";
}
</script>
</head>
<body>

<p 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. This is some text. This is some text.</p>

<input type="button" onclick="displayResult()" value="Set max height">

</body>
</html>

尝试一下 »


Style 对象参考手册 Style 对象