Style minWidthProperty

Style 对象参考手册Style Object

Definition and Usage

The minWidth property sets or returns the minimum width of an element.

The minWidth property only works on block-level elements or elements with absolute/fixed positioning.

Syntax

Set the minWidth property:

Object.style.minWidth="length|%|inherit"

Return the minWidth property:

Object.style.minWidth

Value Description
length Defines the minimum width using units such as px, cm. The default is 0.
% Defines the minimum width as a percentage of the parent element.
inherit The value of the minWidth property is inherited from the parent element.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the minWidth property.

Note:IE7 and earlier versions do not support the "inherit" value. IE8 only supports "inherit" if a !DOCTYPE is specified. IE9 supports "inherit".


Example

Example

Set the minimum width of an element:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
<script>
function displayResult(){
    document.getElementById("p1").style.minWidth="200px";
}
</script>
</head>
<body>

<p style="background:red;width:100px;" id="p1">This paragraph is 100px wide.<br>
When you click the button below,<br>
the minimum width is set to 200px,<br>
so this paragraph is 200px wide.</p>
<input type="button" onclick="displayResult()" value="Set minimum width">

</body>
</html>

Try it yourself »


Style 对象参考手册Style Object Other Extensions