Loading tutorials
:has(), the CSS pseudo-class that lets a rule select an element based on what it contains or what follows it. You will learn what it matches, how to read it, and which mistakes to avoid. Later chapters cover the full syntax, specificity, state, and performance.6 min read:has(): what goes inside the parentheses, how the browser reads it, and which mistakes change the meaning of a rule. It assumes you know basic selectors (type, class, ID, attribute), the four combinators (descendant, >, +, ~), pseudo-classes such as `:hover6 min read:has(): checking whether an element contains something at any depth, and checking whether it contains something as a direct child. It assumes you know basic selectors, the descendant (space) and child (>) combinators, and the idea that a selector's5 min read>, +, ~), how :hover and :invalid work, and the basic :has() syntax from the earlier chapters. Here you will use :has() with the two sibling combinators. The result is that CSS can style an element based on what comes afte6 min read:has(). It assumes you know how specificity works for type, class, and ID selectors, that you can read a specificity triple such as (0,1,1), and that you know the basic :has() syntax from the earlier chapters.5 min read:has() with a relative selector list, such as .card:has(> img). You should also know what :not() and :is() do on their own and how specificity is counted. Here you will combine them, and the main skill is working out which combination expresses the condition5 min read:hover, :checked and :focus-visible, and how specificity is calculated. It also assumes you can write a simple :has() selector with a descendant or a direct child, as covered earlier in this tutorial.6 min read:has() with :nth-child(). This chapter covers how that works, the patterns for "at least", "at most", and "exactly" N children, and the points where these selectors go wrong.6 min read:has() with a relative selector, know the four combinators, and understand the basics of specif6 min read:has() selectors with descendant, child and sibling arguments, and that you know how :not() and :is() combine with them. Here we cover the limits of :has(): what the parser rejects, what it silently ignores, and what the selector cannot observe at all. Know5 min read:has() selectors with descendant, child, and sibling arguments. It also assumes you know how the cascade orders rules. You will learn what makes a :has() selector expensive, which patterns avoid the cost, and how to measure the result in your own page.5 min read:has() selectors, you know how @media and @supports at-rules wrap CSS rules, and you have written basic JavaScript with document.querySelector. It covers which browsers support :has(), how a browser treats a rule it cannot parse, and how to build pages th6 min read:has() works in CSS. That means relative selectors such as :has(> img) and :has(+ p), and the restrictions on nesting and pseudo-elements. It also assumes you know the DOM methods querySelector and querySelectorAll, and how to attach an event listener. Her6 min read