Practical Challenges: Advanced CSS Architecture
Demonstrate your mastery of scalable CSS architecture and naming conventions. These practical exercises test your ability to implement BEM (Block, Element, Modifier) methodology, structure maintainable styles using Native CSS Nesting, and assemble flexible components via Utility-First principles.
Challenge 1: Refactor Legacy CSS to BEM Architectureβ
Objectiveβ
Take a legacy component burdened by deep tag nesting and fragile specificity, and refactor it into clean, maintainable BEM class structures with single-class specificity (0,0,1,0).
Requirementsβ
- Convert all tag selectors to BEM block and element class names (
.article-card,.article-card__header,.article-card__title,.article-card__meta). - Add a
.article-card--featuredblock modifier to update theme colors and borders without increasing CSS specificity. - Ensure elements can never exist outside their base block context conceptually.
Solutionβ
Challenge 2: Native CSS Nesting for Navigation UIβ
Objectiveβ
Construct an interactive header navigation component using modern Native CSS Nesting and parent selector (&) state bindings.
Requirementsβ
- Nest descendant elements directly within the primary
.site-navselector. - Bind state modifiers and pseudo-classes (
:hover,:focus,.site-nav__link--active) directly using the&parent selector. - Nest an
@mediaquery inside the base container to adjust layout direction on larger screens.
Solutionβ
Challenge 3: Composable Utility-First Dashboard Cardβ
Objectiveβ
Assemble a responsive user analytics card exclusively by layering single-purpose utility classes without writing custom, feature-specific semantic rules.
Requirementsβ
- Create atomic helper classes covering layout (
u-flex), spacing (u-gap), colors (u-bg-slate), borders (u-rounded), and typography. - Build a complete UI metric component featuring a status badge, numerical value, and secondary trend text purely through class composition.
Solutionβ
Summary of Module 5 Key Conceptsβ
| Methodology | Core Principle | Primary Advantage |
|---|---|---|
| BEM Conventions | Encapsulate Blocks, Elements, and Modifiers | Eliminates specificity wars and creates self-documenting code |
| Native CSS Nesting | Nest descendant rules and & pseudo-states | Keeps contextual component CSS grouped logically in one place |
| Utility-First | Compose UI using atomic, single-purpose classes | Keeps CSS bundle size constant while enabling rapid prototyping |