CodePark/ questions / Modern CSS
START PRACTICINGPRACTICE
Frontend question · CSS & HTML › Modern CSS

What does .card:has(> img) select?

Every .card that has an img as a direct child

"Every .card that has an img as a direct child" is right. :has() selects the element on its left when the selector inside it matches. So it styles the .card, not the image. The > limits the match to direct children.

"Every
img that is a direct child of a .card" is the tempting wrong answer. That is what .card > img selects. Without the >, any img anywhere inside would count. And .card:has(+ img) would test the next sibling instead.