Enabling selectors beat disabling ones in CSS
CSS-Tricks highlights advice from Silvestar Bistrović on preferring what he calls an "enabling selector": one that "does a job without disabling the particular rule."
The canonical case is setting margin on every element and then stripping it from the last one, because the space lands where you don't want it.
/* "Disabling" rule */
.card:last-child {
margin-bottom: 0;
}
Selecting from the parent is arguably more contextual, though.
.card:not(:last-child) {
margin-bottom: 1rem;
}
Silvestar's point is that these rules only ever apply something — you never apply it and undo it later with a second selector. That pattern, the piece agrees, is harder to follow and easier to break.
The article also points to a scoped form of Lobotomized Owls as another example:
/* Only space them out if they stack */
.card + .card {
margin-top: 1rem;
}
Looking ahead, the piece argues gap is where this is all heading: shift the responsibility to the parent rather than the child, and keep the selector enabling:
.parent-of-cards {
display: grid;
gap: 1rem;
}


