Responsive List of Avatars Using Modern CSS (Part 1)
These articles are AI-generated summaries. Please check the original sources for full details.
Responsive List of Avatars Using Modern CSS
A list of rounded images that slightly overlap each other is a classic web design pattern. The novelty lies in the responsive implementation, dynamically adjusting the overlap between images to fit the container.
Achieving a responsive layout with overlapping elements presents a challenge to traditional web development. Ideal models assume predictable element sizes, but real-world scenarios demand flexibility to accommodate varying screen sizes and content lengths, which can easily lead to layout breaks and visual inconsistencies if not handled correctly.
Key Insights
sibling-count()Support: Currently limited to Chrome and Safari Technology Preview (as of Dec 2025), with Firefox support tracked in Ticket #1953973 and WebKit in Issue #471.- CSS Masking: Utilizing
mask: radial-gradient()to create transparent gaps between images, enhancing visual appeal and complexity. - Container Queries: Employing
container-type: inline-sizeand100cqiunits to accurately calculate responsive margins based on container dimensions, avoiding percentage-based inaccuracies.
Working Example
.container {
--s: 120px; /* image size*/
--g: 10px; /* the gap */
display: flex;
container-type: inline-size;
}
.container img {
width: var(--s);
border-radius: 50%;
--_m: min((100cqw - sibling-count() * var(--s))/(sibling-count() - 1), var(--g));
margin-right: var(--_m);
mask: radial-gradient(50% 50% at calc(150% + var(--_m)),
#0000 calc(100% + var(--g)), #000);
transition: --_m .3s linear;
}
@property --_m {
syntax: "<length>";
inherits: true;
initial-value: 0px
}
.container:not(.reverse) img:last-child {
mask: none;
margin: 0;
}
.container:not(.reverse):has(:not(:last-child):hover) img:not(:hover) {
--_m: min((100cqw - var(--g) - sibling-count()*var(--s))/(sibling-count() - 2),var(--g));
}
Practical Applications
- Profile Galleries: Social media platforms or team directories could use this pattern to display user avatars in a visually engaging and responsive manner.
- Pitfall: Over-reliance on pixel-based margins can lead to layout issues on different screen densities. Using relative units like
cqwandcqiis crucial for consistent rendering.
References:
Continue reading
Next article
Terraform Workspaces for Isolated Infrastructure
Related Content
Interop 2026: Major CSS Features Gain Cross-Browser Consistency
Interop 2026 initiative ensures consistent cross-browser support for advanced CSS features like Anchor Positioning, Container Style Queries, and Scroll-Driven Animations.
Building Scrollytelling Experiences with CSS Scroll-Snap Events and Scroll-Driven Animation
Lee Meyer demonstrates how to utilize emergent Chromium-based scroll-snap events and scroll-state queries to create complex, interactive scrollytelling experiences.
CSS Evolution: From random() Functions to Full DOOM Rendering
Explore the latest CSS advancements including random() functions, anchored container queries, and a full DOOM engine rendered using 3D transforms and clipping paths.