Home > Web Front-end > CSS Tutorial > Why Does My Flex Child Exceed Parent Height in Firefox but Not Chrome?

Why Does My Flex Child Exceed Parent Height in Firefox but Not Chrome?

DDD
Release: 2024-10-24 18:42:02
Original
278 people have browsed it

Why Does My Flex Child Exceed Parent Height in Firefox but Not Chrome?

Preventing Child Flex Item from Exceeding Parent Height

When a flex container contains a child item with both flex: 1 and overflow-y: scroll, a discrepancy between Chrome and Firefox arises. In Chrome, the child item expands to fill the remaining space without exceeding the parent's height, resulting in visible scrollbars. In Firefox, however, the child item's height increases, breaking out of the parent.

Solution

To resolve this issue in Firefox, replace flex: 1 with flex: 1 1 1px. This sets a fixed minimum basis of 1px, ensuring that the child item does not exceed the parent's height even when there is content overflow.

Revised Code

<code class="css">#messagelist {
  flex: 1 1 1px;
}

#messagecontents {
  flex: 1 1 1px;
}</code>
Copy after login

This modification ensures that the child items expand to fill the available space while remaining contained within the flex container. Scrollbars will appear in both Chrome and Firefox, allowing users to view content beyond the visible area.

The above is the detailed content of Why Does My Flex Child Exceed Parent Height in Firefox but Not Chrome?. For more information, please follow other related articles on the PHP Chinese website!

source:php
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template