Use column-count to create pseudo masonry layout

This commit is contained in:
Timothée Goguely 2024-09-11 11:22:14 +02:00
parent bd8135d815
commit 03905dbd83
2 changed files with 17 additions and 9 deletions

View file

@ -2,7 +2,6 @@
<figure <figure
v-if="currentTab === 'all' || isFavorite" v-if="currentTab === 'all' || isFavorite"
class="flex" class="flex"
:style="'--rows: ' + (index % 2 ? 2 : 3)"
> >
<button <button
class="favorite" class="favorite"
@ -63,7 +62,6 @@ figure {
grid-row: span var(--rows); grid-row: span var(--rows);
width: 100%; width: 100%;
height: 100%; height: 100%;
margin: 0;
border-radius: var(--rounded-2xl); border-radius: var(--rounded-2xl);
overflow: hidden; overflow: hidden;
} }

View file

@ -6,9 +6,9 @@
<h2 id="tabslist" class="sr-only">Inspirations</h2> <h2 id="tabslist" class="sr-only">Inspirations</h2>
<Tabs :tabs="tabs" @update:currentTab="changeTab" /> <Tabs :tabs="tabs" @update:currentTab="changeTab" />
<Selector /> <Selector />
<section :id="currentTab" class="inspiration"> <section :id="currentTab" class="inspiration" aria-labelledby="inspiration-title">
<Header :inspiration="currentInspiration" /> <Header :inspiration="currentInspiration" />
<div class="grid masonry"> <div class="masonry flow">
<template <template
v-for="(item, index) in currentInspiration.media" v-for="(item, index) in currentInspiration.media"
:key="item.id" :key="item.id"
@ -69,6 +69,7 @@ const favoriteImages = computed(() => {
function changeTab(newValue) { function changeTab(newValue) {
currentTab.value = newValue; currentTab.value = newValue;
} }
</script> </script>
<style scoped> <style scoped>
@ -78,10 +79,19 @@ function changeTab(newValue) {
} }
/* Masonry */ /* Masonry */
.masonry { @media (min-width: 40rem) {
--gap: var(--space-8); .masonry {
grid-template-columns: repeat(auto-fit, minmax(var(--min, 20rem), 1fr)); column-count: 2;
grid-auto-rows: 12rem; }
grid-auto-flow: dense; }
@media (min-width: 65rem) {
.masonry {
column-count: 3;
}
}
@media (min-width: 90rem) {
.masonry {
column-count: 4;
}
} }
</style> </style>