Latest web development tutorials

HTML DOM Style minWidth property

Style Object Reference Style Objects

Definition and Usage

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

minWidth properties play a role only in the block-level element or elements of absolute / fixed position.

grammar

Setting minWidth properties:

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

Back minWidth properties:

Object.style.minWidth

描述
length 使用 px、cm 等单位定义最小宽度。默认是 0。
% 定义最小宽度为父元素的百分比。
inherit minWidth 属性的值从父元素继承。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support minWidth property.

Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".


Examples

Examples

The minimum width of the element:

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

<p style="background:red;width:100px;" id="p1">这个段落的宽度是100px。<br>
当点击下面的按钮时,<br>
最小宽度被设置为200px,<br>
因此,这一个段落是200像素宽</p>
<input type="button" onclick="displayResult()" value="设置最小宽度">

</body>
</html>

try it"


Style Object Reference Style Objects