Height and width in CSS
Set height and width in CSS
height
and width
properties are used to set the height and width of elements in CSS. They can get the following values:
- auto - is the default mode in which the browser calculates the height and width
- length - value in px, cm .
- percent (%) - the value in percent
div {
height: 200px;
width: 50%;
background-color: powderblue;
}
div {
height: 100px;
width: 500px;
background-color: powderblue;
}
Height and width in CSS Picture 1
The image displayed on the browser of the above two examples
Note: height
and width
properties do not include padding,
borders, and margins. They will determine the height / width of the area inside the element's padding,
border, and margin.
Max-width setting
The max-width
used to select the maximum width for the element, can use the values:
- length - length in px, cm .
- percen (%) - percent
- No - this is the default mode, meaning there is no maximum limit
Possible problems with the card
above is when the browser window is smaller than the element width (500px), the browser will add a vertical scroll bar to the rang. If using
max-width,
the browser will handle it better when the window is small.
Note: max-width
will override the width.
The example below shows the element
has a height of 100px and a maximum width of 500px.
div {
max-width: 500px;
height: 100px;
background-color: powderblue;
}
Previous article: Padding in CSS
The following article: Box Model in CSS
You should read it
- Box Model (Box Model) in CSS
- Max-width, maximum element width in CSS
- Change the width of columns and the height of rows in Excel
- Complete tutorial of Excel 2016 (Part 6): Change the size of columns, rows and cells
- How to change the height or width of the Taskbar on Windows 10
- Simple calculation to know how high your child will be
- CSS Selector in jQuery
- Principles of mezzanine and loft design
- Padding in CSS
- Border in CSS
- Miracle: iPhone free fall from a height of 300 meters still 'survives'
- Outline in CSS