minHeight style property
Specifies or returns a minimum height for the visible area of an element.
This property has effect only on block-level elements or on elements with absolute or fixed position.
The minHeight property contains only the pure height of the visible content, without the padding, scrollbar, border and the margin.
The height of an element can never be less than the value specified by the minHeight property.
object.minHeight;
Note, this property works differently in Internet Explorer, depending on the document type declaration.
For example:
it does not work in case of the HTML 4.01 Transitional document type
The properties mentioned above can be used to access style settings.
If you need the height of a rendered element, you can use the clientHeight, offsetHeight and scrollHeight properties or the getBoundingClientRect method.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
CSS page for this property: min-height |
Possible values:
The type of this property is string.
One of the following values:
The minimum height for the element in length units. For the supported length units, see the length page. | |||||||
The minimum height for the element is the specified percentage of the height of the parent element. | |||||||
Takes the value of this property from the computed style of the parent element. |
Default: 0.
Example HTML code 1:
This example illustrates the use of the min-height property:
|
||||
<!DOCTYPE html> <html> <head> <style> .minHeight { min-height: 100px; overflow: auto; border: 3px solid red; } </style> </head> <body> <table> <tr> <td class="minHeight"> The min-height style property of this <b>table cell</b> is '100px'. <div style="height:30px; background-color:green;">The height of this green field is 30px.</div> </td> </tr> </table> <div class="minHeight"> The min-height style property of this <b>division element</b> is '100px'. <div style="height:30px; background-color:green;">The height of this green field is 30px.</div> </div> </body> </html> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example is equivalent to the previous one, but it uses the HTML 4.01 Transitional document type so the min-height property does not work for td elements in Internet Explorer before version 8:
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <style> .minHeight { min-height: 100px; overflow: auto; border: 3px solid red; } </style> </head> <body> <table> <tr> <td class="minHeight"> The min-height style property of this <b>table cell</b> is '100px'. <div style="height:30px; background-color:green;">The height of this green field is 30px.</div> </td> </tr> </table> <div class="minHeight"> The min-height style property of this <b>division element</b> is '100px'. <div style="height:30px; background-color:green;">The height of this green field is 30px.</div> </div> </body> </html> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 3:
This example illustrates the use of the minHeight property in JavaScript:
|
||||
<!DOCTYPE html> <head> <script type="text/javascript"> function ChangeMinHeight () { var division = document.getElementById ("myDiv"); var input = document.getElementById ("myInput"); division.style.minHeight = input.value + "px"; } </script> </head> <body> <div id="myDiv" style="border: 3px solid red;"> Use the button below to modify the min-height style property of the element that contains this text. <div style="height:50px; background-color:green;">The height of this green field is 50px.</div> </div> <br /><br /> <input id="myInput" type="text" value="100" /> <br /> <button onclick="ChangeMinHeight ();">Change the minHeight of the element!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, htmlElement.style
HTML elements:
address, blockquote, body, center, dd, dir, div, dl, dt, fieldset, form, h1, h2, h3, h4, h5, h6, hr, iframe, img, input:button, input:file, input:image, input:password, input:reset, input:search, input:submit, input:text, isindex, legend, li, listing, marquee, menu, ol, p, plaintext, pre, select, table, textarea, tr, ul, xmp
Related pages:
External links:
min-height (MSDN)
min-height (Mozilla Developer Center)
min-height (Safari Reference Library)
min-height (W3C)
min-height (Mozilla Developer Center)
min-height (Safari Reference Library)
min-height (W3C)
User Contributed Comments