Good Code
The good version uses explicit component classes and a modifier, so a reviewer can see which rule owns each state without tracing through the whole page.
Lesson 02
Keep selectors scoped and low-specificity so styles are easy to override intentionally.
.profile-card {
/* Low-specificity component classes keep ownership easy to review. */
color: #172033;
background: #ffffff;
border: 1px solid #d8dee8;
}
.profile-card--featured {
border-color: #2563eb;
}
.profile-card__title {
color: #0f172a;
}#app main .profile-card.featured div h2.title {
/* This selector wins by force instead of describing component intent. */
color: #0f172a !important;
}
#app main .profile-card div h2.title {
color: #475569;
}The good version uses explicit component classes and a modifier, so a reviewer can see which rule owns each state without tracing through the whole page.
The bad version depends on page structure, ID specificity, and !important, which makes future overrides harder and ties a reusable card to one DOM shape.