Home > Article > Web Front-end > When to use `height: 100%` vs. `min-height: 100%` in CSS?
height:100% vs. min-height:100%
When trying to control the height of an HTML element, CSS offers two significant properties: height and min-height. These properties play distinct roles in determining an element's size.
height:100%
Setting height to 100% indicates that an element should expand to occupy the entire height of its parent container. This means the element's height will adjust dynamically based on the size of its parent.
min-height:100%
On the other hand, min-height specifies a minimum height for an element. If the computed height of the element, considering other factors like content and margins, is less than 100%, min-height enforces a height of 100%. However, if the computed height exceeds 100%, min-height has no effect.
Key Difference
The main difference between height:100% and min-height:100% lies in their behavior when the computed height of an element is less than 100%. Height:100% allows the element to shrink below 100%, while min-height:100% prevents this shrinkage by imposing a minimum height of 100%.
Example
If you have a
The above is the detailed content of When to use `height: 100%` vs. `min-height: 100%` in CSS?. For more information, please follow other related articles on the PHP Chinese website!