float: right 配合不等高圖片導致「階梯狀」錯位:高圖片佔據多行空間,後續浮動元素卡在高度較矮處。
= $img['title'] ?>
.gallery { display: flex; flex-wrap: wrap; gap: 10px; }
.item { flex: 1 1 300px; min-width: 250px; }
.item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 10px;
grid-auto-flow: dense; /* 緊湊填充 */
}
.item img { width: 100%; height: auto; }
include 'template.php' 分離 HTML/邏輯。htmlspecialchars 轉義防 XSS。