width
Description
width
defines the width of an element's content area.
Item | Value |
---|---|
Initial value | auto |
Inherited | No. |
Version | CSS1 |
JavaScript syntax | object.style.width="50px" |
Applies to | Block-level and replaced elements. |
Syntax and Property Values
width: length | percentage | auto | 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>
<style>
p {<!-- w w w.ja v a 2 s .co m-->
margin: 10px;
padding: 10px;
color: black;
border: thin solid;
width: 250px;
top: 100px;
line-height: 3em;
font-size: 1em;
}
</style>
</head>
<body>
<p>
this is a test. java2s.com
this is a test. this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test. this is a test.
</p>
</body>
</html>
The code above generates the following result.