Home  >  Article  >  Web Front-end  >  Why Isn\'t My DIV Height Working with Percentages?

Why Isn\'t My DIV Height Working with Percentages?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-23 20:12:14126browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn