CSS gör det möjligt att ange höjd och bredd på ett element.
<div> Lorem ipsum dolor sit amet consectetur adipiscing </div> <div class="foo"> Lorem ipsum dolor sit amet consectetur adipiscing </div>
Css-egenskaperna "height" och "width" gör det möjligt att kontrollera höjd och bredd på ett element. Värdet kan anges i vanliga måttenheter (px, em), i procent (%) eller "auto".
CSS
div {
background:yellow;/*För att divisionen ska synas*/
height:100px;
width:100px;
}
div.foo {
background:red;
height:50%;
width:80%;
}
Värdet auto gör att elementet anpassar sig efter storleken på innehållet.
CSS
div {
background:yellow;
height:100px;
width:auto;
}
div.foo {
background:blue;
height:50px;
width:auto;
}
CSS-egenskaperna "min-height", "min-width", "max-height" och "max-width" anger den minsta respektive den maximala höjd och bredd ett element kan anta. Standardvärdet är "none".
Använd inte dessa egenskaper eftersom de inte stödjs av Internet Explorer!
CSS
div {
background:yellow;
min-height:10px;
min-width:10%;
}
div.foo {
background:green;
max-height:30%;
max-width:none;
}
The CSS dimension properties allow you to control the height and width of an element. It also allows you to increase the space between two lines.
Browser support: IE: Internet Explorer, F: Firefox, N: Netscape.
W3C: The number in the "W3C" column indicates in which CSS recommendation the property is defined (CSS1 or CSS2).
| Property | Description | Values | IE | F | N | W3C |
|---|---|---|---|---|---|---|
| height | Sets the height of an element | auto length % |
4 | 1 | 6 | 1 |
| max-height | Sets the maximum height of an element | none length % |
- | 1 | 6 | 2 |
| max-width | Sets the maximum width of an element | none length % |
- | 1 | 6 | 2 |
| min-height | Sets the minimum height of an element | length % |
- | 1 | 6 | 2 |
| min-width | Sets the minimum width of an element | length % |
- | 1 | 6 | 2 |
| width | Sets the width of an element | auto % length |
4 | 1 | 4 | 1 |