<div class="group">
<span>Hover me</span>
</div>Option C uses group-hover as the variant and applies the arbitrary selector [&>span] to target the direct child span. This means when the parent div with class group is hovered, the span inside gets the red text color.
Other options either misuse the order or the selector syntax.
element only when the preceding
sibling is focused?
<h2 tabindex="0">Title</h2>
<p>Paragraph</p>.
Option B correctly uses the arbitrary variant [&:focus+p] to target the
that is immediately after the focused element (the
).
Option B incorrectly places focus: before the arbitrary variant, which does not work as intended. Option B targets the wrong element and option B uses the general sibling combinator (~) which is not the immediate sibling.
[&:not(:last-child)]:mb-4 on a list of The arbitrary variant [&:not(:last-child)] applies styles to all elements except the last child. So mb-4 (margin-bottom 1rem) is added to every
<button>Click me</button>
Option A uses the built-in focus-visible variant correctly to apply an outline only when the button is focused via keyboard (not mouse). This improves accessibility by showing focus only when needed.
Option A tries to use arbitrary variants unnecessarily. Option A and D use focus which triggers on mouse focus too, not just keyboard.
- only when the
- is hovered?
<ul class="hover:[&>li]:text-green-500"> <li>Item 1</li> <li>Item 2</li> </ul>
Option A uses the arbitrary variant [&:hover>li] which means when the element itself is hovered, target its direct li children. This correctly applies the green text color to all li inside the hovered ul.
Option A tries to combine hover variant with arbitrary variant incorrectly. Option A applies hover on li instead of ul. Option A nests hover twice incorrectly.