Javascript examples for CSS Style Property:maxWidth
The maxWidth property sets or gets the maximum width of an element.
Value | Description |
---|---|
none | No 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. |
Item | Value |
---|---|
Default Value: | none? |
Return Value: | A String, representing the maximum width of an element |
CSS Version | CSS2 |
Set the maximum width of a <div> element:
<!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>