Coding task · HTML and CSS course · Module 9: Modern CSS
Parent Selectors with :has()
:has() is the 'Eye of Horus' of CSS - it sees what's inside and styles the parent! article:has(img) styles the article when it contains an img. It also works with :not() - article:not(:has(img)) when there is NO image. A revolution in CSS!
Task
Create: article:has(img) { border: 2px solid gold }, article:has(video) { background: #1a1a2e }, article:not(:has(img, video)) { opacity: 0.7 }. Test with different content - the parent reacts to its children!