CSS width property
Examples
Set the height and width of a paragraph:
p.ex
{
height:100px;
width:100px;
}
{
height:100px;
width:100px;
}
try it"
In the bottom of this page for more examples.
Attribute definitions and instructions
width attributes set the width of the element.
Note: width attribute does not include padding, margins and borders!
Defaults: | auto |
---|---|
inherit: | no |
version: | CSS1 |
JavaScript syntax: | object .style.width = "50px" |
Browser Support
Figures in the table represent the first browser to support the version number of the property.
属性 | |||||
---|---|---|---|---|---|
width | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Property Value
value | description |
---|---|
auto | Defaults. Browser calculate the actual width. |
length | Use px, cm other units defined width. |
% | Based on the definition of the percentage of the width of containing block (the parent element). |
inherit | Predetermined width property value should inherit from the parent element. |
More examples
Use a percentage to set the width of the element
This example demonstrates how to use a percentage value to set the width of an element.
related articles
CSS tutorial: CSS a Dimension
CSS tutorial: CSS Box Model
CSS Reference: height attribute