Today I Learned - Rocky Kev

TIL CSS target everything but last element using Not

POSTED ON:

TAGS:

Don't do this:


.item {
margin-right: 1.6rem;
}

.item:last-child {
margin-right: 0;
}

Do this:

/* Option 1 */

.item:not(:last-child) {
margin-right: 1.6rem;
}

/* Option 2 */
.item:nth-child(n+2) {
margin-left: 1.6rem;
}

/* Option 3 */
.item + .item {
margin-left: 1.6rem;
}

REF:
https://betterprogramming.pub/5-css-practices-to-avoid-as-a-web-developer-1b7553c05131


Related TILs

Tagged:

TIL the alternate keyword

If 'alternate' appears along with the stylesheet keyword, the linked file is an alternative stylesheet. It won’t be applied to the document, but it will be ready for when we need it.

TIL Logical Properties

For that sweet sweet Internationalization you want to avoid directional words like 'left', 'right', 'top', and 'bottom'.

TIL Using pseudo-classes in your querySelector!

let notTuna = document.querySelectorAll('.sandwich:not(.tuna)')