minWidth style property
7 | ||||
Specifies or returns the minimum width 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 minWidth property contains only the pure width of the visible content, without the padding, scrollbar, border and the margin.
The width of an element can never be less than the value specified by the minWidth property.
Note that this property works in Internet Explorer only from version 7.
The properties mentioned above can be used to access style settings.
If you need the width of a rendered element, you can use the clientWidth, offsetWidth and scrollWidth 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-width |
Possible values:
The type of this property is string.
One of the following values:
Takes the value of this property from the computed style of the parent element. | |||||||
The minimum width for the element in length units. For the supported length units, see the length page. | |||||||
The minimum width for the element is the specified percentage of the width of the parent element. |
Default: 0.
Example HTML code 1:
This example illustrates the use of the min-width property:
|
||||
<head> <style> .minWidth { width: 100px; min-width: 200px; background: red; } .widthOnly { width: 100px; background: red; } </style> </head> <body> <p class="minWidth"> Element has width: 100px and min-width: 200px. <br /> As a result, it should be 200 pixels wide. </p> <p class="widthOnly"> Element has width: 100px and min-width: 200px. <br /> As a result, it should be 200 pixels wide. </p> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the minWidth property in JavaScript:
|
||||
<head> <script type="text/javascript"> function ChangeMinWidth () { var pObj = document.getElementById ("myP"); var input = document.getElementById ("myInput"); pObj.style.minWidth = input.value + "px"; } </script> </head> <body> <p id="myP" style="width: 50px;background: #33CCFF;">Sample element with width: 50px</p> <input id="myInput" type="text" value="120" /> <br /> <button onclick="ChangeMinWidth ();">Change the minWidth 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, ul, xmp
Related pages:
External links:
min-width (MSDN)
min-width (Mozilla Developer Center)
min-width (Safari Reference Library)
min-width (W3C)
min-width (Mozilla Developer Center)
min-width (Safari Reference Library)
min-width (W3C)
User Contributed Comments