Home >Web Front-end >CSS Tutorial >Why Do Chrome and Firefox Render Percentage Heights Differently on Block-Level Elements?
Question:
When setting a block-level element's height to a percentage (e.g., 1%) without explicitly setting the height of its parent, why do Chrome and Firefox compute the height differently, with Chrome considering the child's bottom margin and Firefox not?
Answer:
The CSS standards state that if the containing block's height is not specified explicitly, a percentage height computes to "auto."
However, different browsers have implemented this provision differently:
This deviation from the spec has led to rendering inconsistencies, with some browsers using flex heights and others requiring a set parent height.
Alternative Solutions:
To ensure consistent rendering in all browsers, consider using one of the following alternatives:
The above is the detailed content of Why Do Chrome and Firefox Render Percentage Heights Differently on Block-Level Elements?. For more information, please follow other related articles on the PHP Chinese website!