I have an HTML page with fixed height header and footer and a element in between.
I want the element to have always the total height of the screen (excluding the h
Here is a quick tip for creating responsive elements that retain their aspect ratio as they scale.
However, when we specify a padding-bottom value for the same element, the padding measurement is calculated relative to the element’s width:
.rect {
width: 100%;
height: 0;
padding-bottom: 50%;
}
Correct aspect ratio
You will notice that I have set the element’s height property to 0, to ensure that the height of any child elements will not be added to the padding value when the visible height is calculated.
A note about child elements
If you also want to specify percentage based heights for a child element, you will need to assign an absolute or relative position value to both the parent and the child:
.rect {
position: relative;
width: 100%;
height: 0;
padding-bottom: 50%;
}
.rect p {
position: absolute;
margin: 0;
height: 100%;
}
View A Demo