I have a div, and the maximum width for this div is user defined. I know I can get it done using element.style.height but this doesn't work in IE.
Any ideas on how to implement the max-height equivalent of Firefox by using javascript?
The max-height CSS property sets the maximum height of an element. It prevents the used value of the height property from becoming larger than the value specified for max-height .
A height of 100vh corresponds to the maximum possible viewport height. Since the initial viewport height is smaller, the body element with a min-height of 100vh initially exceeds the viewport height regardless of its content.
The max-height property in CSS is used to set the maximum height of a specified element. Authors may use any of the length values as long as they are a positive value. max-height overrides height, but min-height always overrides max-height .
Usually style attribute names are translated into javascript property names by removing the hyphens and camelcase the name instead.
So background-color
becomes backgroundColor
, text-align
becomes textAlign
and max-height
becomes maxHeight
.
You can set an element el
's maximum height to mHeight
by:
el.style.maxHeight=mHeight;
Remember to use a valid value for mHeight
.
document.getElementById ( "yourelementid" ).style.maxHeight = "100px";
See maxHeight Property
maxHeight was introduced in Windows Internet Explorer 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With