max-width
Description
max-width
sets a maximum constraint on the width of the element.
Item | Value |
---|---|
Initial value | none |
Inherited | No. |
Version | CSS2 |
JavaScript syntax | object.style.maxWidth="10px" |
Applies to | All elements except inline nonreplaced elements and table elements. |
Syntax and Property Values
max-width: length | percentage | inherit
The property values are listed in the following table.
Value | Description |
---|---|
auto | Default value. The browser does the calculation. |
length | Set width in px, cm, etc. |
% | Set width in percent of the containing element |
inherit | Inherit the width property from the parent element |
Example
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<style type='text/css'>
p {<!--from w w w . j av a2s . c o m-->
padding: 10px;
margin: 10px;
border: thin solid black;
width: auto;
max-width: 500px;
}
</style>
</head>
<body>
<p>
This is a test. This is a test.
</p>
</body>
</html>
The code above generates the following result.