WeSearch

CSS :has() Selector: The Layout Trick I Wish I Knew 5 Years Ago

·9 min read · 0 reactions · 0 comments · 10 views
#css#web development#frontend
CSS :has() Selector: The Layout Trick I Wish I Knew 5 Years Ago
⚡ TL;DR · AI summary

The CSS :has() selector has become a valuable tool for frontend developers, allowing for more dynamic styling without the need for additional JavaScript. It enables developers to style elements based on their children or siblings, simplifying layouts and improving efficiency. This selector has been implemented in major browsers and has proven beneficial in real-world projects.

Key facts
Original article
DEV.to (Top)
Read full at DEV.to (Top) →
Opening excerpt (first ~120 words) tap to expand

try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 3798270) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } Richard Lemon Posted on May 23 • Originally published at richardlemon.com CSS :has() Selector: The Layout Trick I Wish I Knew 5 Years Ago CSS :has() is not just a fancy :parent When :has() started popping up in specs and tweets, I mentally filed it under “cool, but not for shipping work.” I was wrong. Now it is in Chrome, Safari, Edge, and Firefox. I use it in real projects. It has removed entire JavaScript files and a pile of .is-active classes that I was embarrassed to maintain.

Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from DEV.to (Top)