CSS width 属性
- previous page widows
- next page word-break
Definition and usage
The width property sets the width of the element.
Description
This property defines the width of the element's content area, where padding, borders, and margins can be added outside the content area.
Inline non-replaced elements will ignore this property.
See also:
CSS Tutorial:CSS Dimensions
CSS Tutorial:CSS 框模型概述
CSS Reference Manual:height property
HTML DOM Reference Manual:width property
CSS syntax
width: auto|value|initial|inherit;
Attribute value
Value | Description |
---|---|
auto | Default value. The browser can calculate the actual width. |
length | Define the width using units such as px, cm, etc. |
% | Define a percentage width based on the width of the containing block (parent element). |
inherit | Specifies that the width property should inherit its value from the parent element. |
Technical details
Default value: | auto |
---|---|
Inheritance: | no |
Version: | CSS1 |
JavaScript syntax: | object.style.width="50px" |
TIY example
- Set the width of an element using pixel values
- This example demonstrates how to set the width of an element using pixel values.
- Set the width of an element using percentage
- This example demonstrates how to set the width of an element using percentage values.
Browser support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | IE / Edge | Firefox | Safari | Opera |
---|---|---|---|---|
1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
- previous page widows
- next page word-break