Home > Article > Web Front-end > Why Isn\'t My DIV Height Working with Percentages?
Percentages Not Working for DIV Height? Check Your Parent Elements!
In the code snippet provided, the DIV element's height is set to 100%, but it remains undisplayed. The reason lies in the absence of 100% height on the parent elements, body and html.
When using percentages for height, it's crucial to ensure that all parent elements have their height set to 100% as well. This allows the DIV to inherit the full height of its container.
html, body { height: 100%; width: 100%; margin: 0; }
With the parent elements' height set to 100%, the DIV element now properly expands to fill its container's height.
The above is the detailed content of Why Isn\'t My DIV Height Working with Percentages?. For more information, please follow other related articles on the PHP Chinese website!