Home > Web Front-end > CSS Tutorial > How Can I Make a Floated Div 100% of its Parent's Height?

How Can I Make a Floated Div 100% of its Parent's Height?

Barbara Streisand
Release: 2024-12-12 13:18:17
Original
808 people have browsed it

How Can I Make a Floated Div 100% of its Parent's Height?

Achieving 100% Height for Floated Div within Parent

When trying to set a floated div to 100% height of its parent, you may encounter a challenge where the inner div renders with a height of 0px. This behavior is attributed to the default vertical alignment for HTML elements. To address this issue, you must configure the display property of the parent div to enable vertical alignment.

Solution:

To force the inner div to match the parent's height, modify the CSS as follows:

#outer {
  display: flex;
  /* Add necessary prefixes for cross-browser compatibility. */
}
Copy after login

Additional Considerations:

  • Prefixes: It's important to add appropriate CSS vendor prefixes for cross-browser compatibility.
  • Internet Explorer: Due to its limited support for Flexbox, Internet Explorer 9 and earlier may not display the layout correctly.
  • Alignment: By default, the align-items property for the parent is set to "stretch," which means the child elements, including the inner div, will vertically align and stretch to fill the available space. If you need different alignment for the child div, you can use the align-self property.

Live Example:

Click the following link for a live JSFiddle demonstration: https://jsfiddle.net/bv71tms5/2/

The above is the detailed content of How Can I Make a Floated Div 100% of its Parent's Height?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template