Home >Web Front-end >CSS Tutorial >Why Doesn't My Child DIV Inherit 100% Height From Its Floated Parent?

Why Doesn't My Child DIV Inherit 100% Height From Its Floated Parent?

Barbara Streisand
Barbara StreisandOriginal
2024-12-08 13:42:13810browse

Why Doesn't My Child DIV Inherit 100% Height From Its Floated Parent?

Enforcing 100% Height for Child DIV Within Floated Parent

In the provided HTML and CSS, the inner DIV's height remains at 0px despite efforts to declare it as 100% of the parent's height.

Solution:

To resolve this issue, the parent DIV, "outer," requires a "display: flex" property to enable flexbox functionality:

#outer {
  display: flex;
}

Flexbox introduces support for flexible layouts, allowing the inner DIV, "inner," to expand vertically and occupy the full height of its parent.

Additional Considerations:

  1. Browser Compatibility: Flexbox is widely supported by modern browsers but may pose compatibility concerns with older versions of Internet Explorer (e.g., IE9). Use prefixes to ensure compatibility across various browsers.
  2. Align Items vs. Align Self: "align-items" is a property for the parent that determines the vertical alignment of its children. Its default value is "stretch," stretching all children vertically to fill the available height. If a different alignment is desired for the child DIV, use the "align-self" property.
  3. JS Fiddle Example: Visit https://jsfiddle.net/bv71tms5/2/ to see a working example of the suggested solution.

The above is the detailed content of Why Doesn't My Child DIV Inherit 100% Height From Its Floated Parent?. 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