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. |
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 |
width |
Yes | Yes | Yes | Yes | Yes |
An example showing how to use width CSS property.
<!DOCTYPE HTML>
<html>
<head>
<style>
p {<!-- w w w.j ava 2s. c o 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>