at (8,8) content-size 367x17.46875 [BFC] children: inline
+ line 0 width: 9.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 1, rect: [8,8 9.34375x17.46875]
+ "a"
+ TextNode <#text>
+ BlockContainer
at (425,8) content-size 367x17.46875 [BFC] children: inline
+ line 0 width: 9.46875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 1, rect: [425,8 9.46875x17.46875]
+ "b"
+ TextNode <#text>
+
+ViewportPaintable (Viewport<#document>) [0,0 800x600]
+ PaintableWithLines (BlockContainer) [0,0 800x33.46875]
+ PaintableWithLines (BlockContainer) [8,8 784x17.46875]
+ PaintableBox (Box
.grid) [8,8 784x17.46875]
+ PaintableWithLines (BlockContainer
) [8,8 367x17.46875]
+ TextPaintable (TextNode<#text>)
+ PaintableWithLines (BlockContainer
) [425,8 367x17.46875]
+ TextPaintable (TextNode<#text>)
diff --git a/Tests/LibWeb/Layout/input/grid/columns-auto-fill-with-gap-2.html b/Tests/LibWeb/Layout/input/grid/columns-auto-fill-with-gap-2.html
new file mode 100644
index 0000000000..70e953d231
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/grid/columns-auto-fill-with-gap-2.html
@@ -0,0 +1,10 @@
+
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
index 832654e67d..0d9b407847 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
@@ -107,8 +107,8 @@ int GridFormattingContext::count_of_repeated_auto_fill_or_fit_tracks(Vector
width.to_px_or_zero());
}
- if (sum_of_grid_track_sizes == 0)
+ auto free_space = get_free_space(*m_available_space, GridDimension::Column).to_px_or_zero();
+ auto const& column_gap = grid_container().computed_values().column_gap();
+ free_space -= repeat_track_list.size() * column_gap.to_px(grid_container(), m_available_space->width.to_px_or_zero());
+ if (free_space <= 0 || sum_of_grid_track_sizes == 0)
return 0;
- return max(1, (get_free_space(*m_available_space, GridDimension::Column).to_px_or_zero() / sum_of_grid_track_sizes).to_int());
+ return (free_space / sum_of_grid_track_sizes).to_int();
// For the purpose of finding the number of auto-repeated tracks in a standalone axis, the UA must
// floor the track size to a UA-specified value to avoid division by zero. It is suggested that this