maxWidth Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:maxWidth

Description

The maxWidth property sets or gets the maximum width of an element.

Property Values

Value Description
noneNo limit on the width of the element. This is default
length maximum width in length units
% maximum width in percentage of the parent element
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: none?
Return Value: A String, representing the maximum width of an element
CSS VersionCSS2

Set the maximum width of a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<div style="background:red;max-width:60px;" id="myDiv">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</div><br>

<button type="button" onclick="myFunction()">test</button>

<script>
function myFunction() {/* ww w  .j  a v a  2 s  .  c  om*/
    document.getElementById("myDiv").style.maxWidth = '10px';
}
</script>

</body>
</html>

Related Tutorials