How to Stretch a Flex Child to Fill the Container Height
When working with Flexbox, it's common to encounter the issue where a child element does not stretch to the full height of its container. This is often due to incorrect usage of the height: 100% property.
In Flexbox, the height: 100% property can be problematic because:
The solution is to remove the height: 100% property and rely on Flexbox's default behavior. By default, flex items in a row direction (the typical layout) align vertically with the property align-items: stretch. This means that the child element will automatically stretch to fill the available height of the container.
Here's an example that demonstrates the correct usage without height: 100%:
some
cool
text
In this example, the yellow child will stretch to fill the height of the container, regardless of the height of the blue child's text. This is because the default align-items: stretch value ensures that flex items are vertically stretched to occupy the available space.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3