Lab 04: Modern CSS Features
Overview
Step 1: Native CSS Nesting
/* CSS nesting (baseline 2023) — no preprocessor needed */
.card {
background: white;
border-radius: 8px;
padding: 1rem;
/* Nested: & refers to .card */
& .card__title {
font-size: 1.25rem;
color: #111;
}
/* Pseudo-class on the parent */
&:hover {
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
transform: translateY(-2px);
}
/* Pseudo-element */
&::before {
content: '';
display: block;
height: 4px;
background: var(--color-primary);
border-radius: 8px 8px 0 0;
}
/* Modifier (BEM-like) */
&.card--featured {
border-color: gold;
}
/* Descendant (without &) — shorthand */
.card__body {
color: #666;
line-height: 1.6;
}
/* Media query inside rule */
@media (min-width: 768px) {
& {
padding: 1.5rem;
}
}
/* Container query inside rule */
@container (min-width: 400px) {
& {
display: flex;
gap: 1rem;
}
}
}Step 2: @scope
Step 3: Advanced :has() Patterns
Step 4: CSS Anchor Positioning
Step 5: View Transitions API
Step 6: Scroll-Driven Animations
Step 7: Scroll Snap
Step 8: Capstone — CSS Feature Compatibility Checker
Summary
Feature
Syntax
Support 2024
Last updated
