diff --git a/Libraries/LibWeb/Layout/FormattingContext.cpp b/Libraries/LibWeb/Layout/FormattingContext.cpp index f878cf6f450..085eb785d5e 100644 --- a/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1609,6 +1609,8 @@ CSSPixels FormattingContext::calculate_inner_width(Layout::Box const& box, Avail CSSPixels FormattingContext::calculate_inner_height(Box const& box, AvailableSpace const& available_space, CSS::Size const& height) const { if (height.is_auto() && box.has_preferred_aspect_ratio()) { + if (*box.preferred_aspect_ratio() == 0) + return CSSPixels(0); return m_state.get(box).content_width() / *box.preferred_aspect_ratio(); } diff --git a/Libraries/LibWeb/Layout/LayoutState.cpp b/Libraries/LibWeb/Layout/LayoutState.cpp index 23651feba1c..795e8da0b95 100644 --- a/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Libraries/LibWeb/Layout/LayoutState.cpp @@ -604,7 +604,7 @@ void LayoutState::UsedValues::set_node(NodeWithStyle& node, UsedValues const* co if (m_has_definite_width && m_has_definite_height) { // Both width and height are definite. } else if (m_has_definite_width) { - m_content_height = clamp_to_max_dimension_value(m_content_width / *aspect_ratio); + m_content_height = *aspect_ratio == 0 ? 0 : clamp_to_max_dimension_value(m_content_width / *aspect_ratio); m_has_definite_height = true; } else if (m_has_definite_height) { m_content_width = clamp_to_max_dimension_value(m_content_height * *aspect_ratio); diff --git a/Tests/LibWeb/Text/expected/css/small-aspect-ratio.txt b/Tests/LibWeb/Text/expected/css/small-aspect-ratio.txt index 1bfe75352f4..45dcddc2eb5 100644 --- a/Tests/LibWeb/Text/expected/css/small-aspect-ratio.txt +++ b/Tests/LibWeb/Text/expected/css/small-aspect-ratio.txt @@ -1 +1,3 @@ element height: 10px +element height: 0px +element height: 0px diff --git a/Tests/LibWeb/Text/input/css/small-aspect-ratio.html b/Tests/LibWeb/Text/input/css/small-aspect-ratio.html index 7de9331f0fe..1f35e0729ff 100644 --- a/Tests/LibWeb/Text/input/css/small-aspect-ratio.html +++ b/Tests/LibWeb/Text/input/css/small-aspect-ratio.html @@ -2,11 +2,18 @@