diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index bdfe46902e..eb20ab831c 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -1301,7 +1301,7 @@ void FlexFormattingContext::distribute_any_remaining_free_space() CSSPixels initial_offset = 0; auto number_of_items = flex_line.items.size(); - if (auto_margins == 0) { + if (auto_margins == 0 && number_of_items > 0) { switch (flex_container().computed_values().justify_content()) { case CSS::JustifyContent::Start: case CSS::JustifyContent::FlexStart: diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp index 33f7039823..f92765f5f0 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -785,6 +785,9 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_base_si affected_tracks.append(track); } + if (affected_tracks.size() == 0) + return; + for (auto& track : affected_tracks) track.item_incurred_increase = 0; @@ -870,6 +873,9 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_growth_ for (auto& track : affected_tracks) track.item_incurred_increase = 0; + if (affected_tracks.size() == 0) + return; + // 1. Find the space to distribute: CSSPixels spanned_tracks_sizes_sum = 0; for (auto& track : spanned_tracks) {