Home  >  Article  >  Web Front-end  >  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
DDDOriginal
2024-10-24 18:42:02167browse

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>

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!

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