CSS Custom Properties, Sibling Hover Dimming via :has(), Aspect Ratio & Scroll Snap
CSS variables (--var-name) allow dynamic theming that cascades down the DOM tree without reloading or CSS preprocessing.
Notice how the background, border, typography color, and button style adapt synchronously through CSS Custom Properties!
:root {
--bg: #f8fafc;
--card: #ffffff;
--primary: #008080;
--text: #1e293b;
}
.theme-dark {
--bg: #0f172a;
--card: #1e293b;
--primary: #38bdf8;
--text: #f8fafc;
}
Hover over any card below. Notice how all other cards dim smoothly, focusing attention on the active element — achieved purely in CSS without JS mouse event handlers!
/* When container has a hovered child, dim all other children */
.container:has(.item:hover) .item:not(:hover) {
opacity: 0.35;
transform: scale(0.95);
}
.item:hover {
transform: scale(1.05);
}
Replace older padding-top: 56.25% hacks with modern native aspect-ratio for responsive video wrappers and square avatars.
.video-box { aspect-ratio: 16 / 9; }
.avatar-box { aspect-ratio: 1 / 1; }
.photo-box { aspect-ratio: 4 / 3; }
Smooth touch and mouse scrolling carousel that snaps to cards automatically. Scroll horizontally below!
.carousel {
display: flex;
overflow-x: auto;
scroll-snap-type: x mandatory;
scroll-behavior: smooth;
}
.card {
scroll-snap-align: center;
}
Modern CSS supports native nesting without preprocessors, cascade layers (@layer) for controlling specificity wars, and scoped styles (@scope).
No Sass/Less required! & syntax works natively in evergreen browsers.
@layer components { .btn { ... } } guarantees priority order regardless of selector weight. @scope (.card) to (.content) creates donut scopes that don't leak styles!
/* Native CSS Nesting */
.card {
background: #f8fafc;
& .btn {
background: teal;
&:hover { background: darkcyan; }
}
}
/* Cascade Layers & Scoped Styles */
@layer reset, base, components, utilities;
@scope (.card) to (.card-body) { p { color: #475569; } }
/* Native Color Mixing */
.mixed { background: color-mix(in srgb, var(--primary) 75%, white); }
/* Typography Balancers & Monospace Numerals */
h1 { text-wrap: balance; }
p { text-wrap: pretty; }
.timer { font-variant-numeric: tabular-nums; }
/* Multiline Truncation */
.clamp-3 {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}