Set the maximum height of a <div> element:
document.getElementById("myDIV").style.maxHeight = "15px";
Try it Yourself »
The maxHeight property sets or returns the maximum height of an element.
The maxHeight property has effect only on block-level elements or on elements with absolute or fixed position.
Note: The height of an element can never be greater than the value specified by the maxHeight property.
Tip: To set or return the minimum height of an element, use the minHeight property.
Property | |||||
---|---|---|---|---|---|
maxHeight | Yes | Yes | Yes | Yes | Yes |
Return the maxHeight property:
object.style.maxHeight
Set the maxHeight property:
object.style.maxHeight = "none|
length|%|initial|inherit"
Value | Description |
---|---|
none | No limit on the height of the element. This is default |
length | Defines the maximum height in length units |
% | Defines the maximum height in % of the parent element |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Default Value: | none |
---|---|
Return Value: | A String, representing the maximum height of an element |
CSS Version | CSS2 |
Return the maximum height of a <div> element:
alert(document.getElementById("myDIV").style.maxHeight);
Try it Yourself »
CSS tutorial: CSS Dimension
CSS reference: max-height property
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!