Set the minimum height of a <div> element:
document.getElementById("myDIV").style.minHeight = "100px";
Click the button to make sure that the DIV element's height never becomes less than 400 pixels:
<!DOCTYPE html> <html> <head> <style> #myDIV {// ww w. ja v a 2 s . c o m width: 500px; background-color: lightblue; overflow: auto; } </style> </head> <body> <button onclick="myFunction()">Test</button> <div id="myDIV"> <p>This DIV element does not have a pre-defined height.</p> <p>The height of this DIV element depends on its content.</p> <p>But if you click the "Test" button, yo will make sure that this DIV element does not become less than 400 pixels in height.</p> </div> <script> function myFunction() { document.getElementById("myDIV").style.minHeight = "400px"; } </script> </body> </html>
The minHeight property sets or gets the minimum height of an element.
The minHeight property has effect only on block-level elements or on elements with absolute or fixed position.
Property Values
Value | Description |
---|---|
length | Sets the minimum height in length units. Default is 0 |
% | Sets the minimum height in % of the parent element |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The minHeight property Default Value: 0
The minHeight property returns a String representing the minimum height of an element.