Skip to content

Commit f537757

Browse files
committed
update layout for project cards
1 parent 5029941 commit f537757

File tree

2 files changed

+16
-68
lines changed

2 files changed

+16
-68
lines changed

src/components/ProjectCard.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const { projectLink, logoLink, name, description, tags = [], loadIssues = false
5858
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
5959
height: auto;
6060
min-height: 200px;
61+
margin-bottom: 1.5rem;
6162
position: relative;
6263
}
6364

src/components/ProjectList.astro

Lines changed: 15 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ const allTags = [...new Set(projectList.flatMap(project => project.tags || []))]
2828

2929
<section id="project-list" class="containerLayout">
3030
{projectList.map((item) => (
31-
<div class="masonry-item">
32-
<ProjectCard
33-
name={item.name}
34-
logoLink={item.imageSrc}
35-
projectLink={item.projectLink}
36-
description={item.description}
37-
tags={item.tags}
38-
loadIssues={item.loadIssues}
39-
/>
40-
</div>
31+
<ProjectCard
32+
name={item.name}
33+
logoLink={item.imageSrc}
34+
projectLink={item.projectLink}
35+
description={item.description}
36+
tags={item.tags}
37+
loadIssues={item.loadIssues}
38+
/>
4139
))}
4240
</section>
4341

@@ -116,51 +114,8 @@ const allTags = [...new Set(projectList.flatMap(project => project.tags || []))]
116114
// Initial filter (show all)
117115
filterProjects();
118116

119-
// Masonry layout function
120-
function initMasonry() {
121-
const container = document.getElementById('project-list');
122-
const items = Array.from(container.querySelectorAll('.masonry-item'));
123-
124-
if (items.length === 0) return;
125-
126-
// Reset positioning
127-
items.forEach(item => {
128-
item.style.position = 'absolute';
129-
item.style.top = '0';
130-
item.style.left = '0';
131-
});
132-
133-
// Calculate positions
134-
const containerWidth = container.offsetWidth;
135-
const gap = 24; // 1.5rem = 24px
136-
const itemWidth = (containerWidth - 2 * gap) / 3; // 3 columns
137-
138-
const columns = [0, 0, 0]; // Track height of each column
139-
140-
items.forEach((item, index) => {
141-
const columnIndex = index % 3; // Fill by rows (0, 1, 2, 0, 1, 2...)
142-
const x = columnIndex * (itemWidth + gap);
143-
const y = columns[columnIndex];
144-
145-
item.style.position = 'absolute';
146-
item.style.left = x + 'px';
147-
item.style.top = y + 'px';
148-
item.style.width = itemWidth + 'px';
149-
150-
// Update column height
151-
columns[columnIndex] += item.offsetHeight + gap;
152-
});
153-
154-
// Set container height
155-
container.style.height = Math.max(...columns) + 'px';
156-
}
157-
158-
// Initialize masonry on load and resize
159-
window.addEventListener('load', initMasonry);
160-
window.addEventListener('resize', initMasonry);
161-
162-
// Re-initialize masonry after issues load
163-
setTimeout(initMasonry, 2000); // Wait for issues to load
117+
// No JavaScript needed for masonry layout anymore!
118+
// CSS Grid handles the masonry layout automatically
164119
</script>
165120

166121
<style>
@@ -224,15 +179,12 @@ const allTags = [...new Set(projectList.flatMap(project => project.tags || []))]
224179
}
225180

226181
.containerLayout {
227-
position: relative;
182+
columns: 3;
183+
column-gap: 1.5rem;
228184
padding: 2rem 1rem;
185+
break-inside: avoid;
229186
}
230187

231-
.masonry-item {
232-
position: absolute;
233-
width: calc(33.333% - 1rem);
234-
min-width: 300px;
235-
}
236188

237189
@media (max-width: 768px) {
238190
#container {
@@ -252,15 +204,10 @@ const allTags = [...new Set(projectList.flatMap(project => project.tags || []))]
252204
}
253205

254206
.containerLayout {
207+
columns: 1;
208+
column-gap: 1rem;
255209
padding: 1rem 0.5rem;
256210
}
257211

258-
.masonry-item {
259-
position: relative !important;
260-
width: 100% !important;
261-
min-width: unset !important;
262-
top: auto !important;
263-
left: auto !important;
264-
}
265212
}
266213
</style>

0 commit comments

Comments
 (0)