0% found this document useful (0 votes)
60 views

CSS Height and Width

The document discusses CSS height, width, and max-width properties. It explains that height and width set the inner dimensions of an element, excluding padding, borders, and margins. Max-width sets the maximum allowable width, which can improve browser handling for smaller windows compared to a fixed width. Both width and max-width accept length values or percentages, with max-width defaulting to none and taking precedence over width if both are set.

Uploaded by

Leslie Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

CSS Height and Width

The document discusses CSS height, width, and max-width properties. It explains that height and width set the inner dimensions of an element, excluding padding, borders, and margins. Max-width sets the maximum allowable width, which can improve browser handling for smaller windows compared to a fixed width. Both width and max-width accept length values or percentages, with max-width defaulting to none and taking precedence over width if both are set.

Uploaded by

Leslie Perez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CSS Height and Width

CSS Height and Width


The CSS height and width properties are used to set the height and width of an element.

The CSS max-width property is used to set the maximum width of an element.
CSS Setting height and width
The height and width properties are used to set the height and width of an element.

The height and width properties do not include padding, borders, or margins. It sets the
height/width of the area inside the padding, border, and margin of the element.
CSS Setting height and width
The height and width properties may have the following values:

auto - This is default. The browser calculates the height and width
length - Defines the height/width in px, cm etc.
% - Defines the height/width in percent of the containing block
initial - Sets the height/width to its default value
inherit - The height/width will be inherited from its parent value
CSS Setting height and width

div {
  height: 200px;
  width: 50%;
  background-color: powderblue;
}
Setting max-width
The max-width property is used to set the maximum width of an element.

The max-width can be specified in length values, like px, cm, etc., or in percent (%) of the
containing block, or set to none (this is default. Means that there is no maximum width).

The problem with the <div> above occurs when the browser window is smaller than the width
of the element (500px). The browser then adds a horizontal scrollbar to the page.

Using max-width instead, in this situation, will improve the browser's handling of small windows.
Setting max-width
Note: If you for some reason use both the width property and the max-width property on the
same element, and the value of the width property is larger than the max-width property; the
max-width property will be used (and the width property will be ignored).
Setting max-width
div {
  max-width: 500px;
  height: 100px;
  background-color: powderblue;
}

You might also like