From eeb2e1566f0c8047a2102f7fff2bb8fa47caad51 Mon Sep 17 00:00:00 2001 From: krek0 Date: Sun, 30 Aug 2026 03:44:10 +0200 Subject: [PATCH] fix: prevent last gallery row from overflowing container --- photologue/static/gallery_justified.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/photologue/static/gallery_justified.js b/photologue/static/gallery_justified.js index e162011..cec2070 100644 --- a/photologue/static/gallery_justified.js +++ b/photologue/static/gallery_justified.js @@ -43,10 +43,10 @@ const sumRatios = ratios.slice(start, end).reduce((a, b) => a + b, 0); const totalSpacing = SPACING * (count - 1); - // Don't stretch the last row if it's not full - const rowHeight = isLastRow && count < 3 - ? TARGET_HEIGHT - : (containerWidth - totalSpacing) / sumRatios; + // Fill the container width, except for a last row that isn't full: + // it keeps the target height, but never wider than the container. + const fitHeight = (containerWidth - totalSpacing) / sumRatios; + const rowHeight = isLastRow ? Math.min(TARGET_HEIGHT, fitHeight) : fitHeight; let left = PADDING; for (let i = start; i < end; i++) {