0
0
Tailwindmarkup~20 mins

Peer modifier (sibling state reaction) in Tailwind - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Peer Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2:00remaining
What is the visual output when hovering the button?

Given this HTML and Tailwind CSS, what color will the <span> text become when you hover over the <button>?

<button class="peer hover:bg-blue-500 p-2">Hover me</button>
<span class="peer-hover:text-red-600">Change me</span>
Tailwind
<button class="peer hover:bg-blue-500 p-2">Hover me</button>
<span class="peer-hover:text-red-600">Change me</span>
AThe span text turns blue when hovering the button.
BThe span text turns red when hovering the button.
CThe span text turns red when hovering the span itself.
DThe span text never changes color on hover.
Attempts:
2 left
💡 Hint

Remember, peer-hover applies styles to siblings when the peer is hovered.

layout
intermediate
2:00remaining
How does the peer modifier affect sibling layout on focus?

Consider this snippet:

<input type="checkbox" class="peer hidden" id="toggle" />
<label for="toggle" class="cursor-pointer">Toggle</label>
<div class="peer-checked:block hidden p-4 bg-green-200">Content</div>

What happens to the <div> when the checkbox is checked?

Tailwind
<input type="checkbox" class="peer hidden" id="toggle" />
<label for="toggle" class="cursor-pointer">Toggle</label>
<div class="peer-checked:block hidden p-4 bg-green-200">Content</div>
AThe div becomes visible only when the label is hovered.
BThe div remains hidden regardless of checkbox state.
CThe div becomes visible (block) when the checkbox is checked.
DThe div becomes visible when the checkbox is focused but not checked.
Attempts:
2 left
💡 Hint

Think about how peer-checked works with hidden inputs.

🧠 Conceptual
advanced
2:00remaining
Why does the peer modifier not work on non-sibling elements?

Given this structure:

<div>
  <button class="peer">Click</button>
  <section>
    <span class="peer-hover:text-blue-600">Text</span>
  </section>
</div>

Why does the peer-hover class on the span not change its color when hovering the button?

Tailwind
<div>
  <button class="peer">Click</button>
  <section>
    <span class="peer-hover:text-blue-600">Text</span>
  </section>
</div>
ABecause peer-hover only works on parent elements, not siblings.
BBecause the button needs a hover class for peer-hover to work.
CBecause the span needs the peer class, not the button.
DBecause <code>peer-hover</code> only works on direct siblings, and the span is nested inside a section.
Attempts:
2 left
💡 Hint

Think about the relationship between peer and the element using peer-hover.

accessibility
advanced
2:00remaining
How to ensure keyboard users see peer-hover effects?

Which approach ensures that keyboard users see the same peer-hover styles when focusing the peer element?

<button class="peer hover:bg-yellow-300">Focus me</button>
<div class="peer-hover:text-yellow-600">Highlight me</div>
Tailwind
<button class="peer hover:bg-yellow-300">Focus me</button>
<div class="peer-hover:text-yellow-600">Highlight me</div>
AAdd <code>peer-focus:text-yellow-600</code> to the div to react on keyboard focus.
BAdd <code>focus-visible:bg-yellow-300</code> to the button only.
CAdd <code>hover:text-yellow-600</code> to the div instead of peer-hover.
DNo changes needed; keyboard users see hover styles automatically.
Attempts:
2 left
💡 Hint

Keyboard users trigger focus, not hover.

📝 Syntax
expert
2:00remaining
What error occurs with this incorrect peer modifier usage?

What happens when you use this class?

<button class="peer-hover:bg-red-500">Click</button>

Why?

Tailwind
<button class="peer-hover:bg-red-500">Click</button>
ANo style changes occur because peer-hover requires the element to be a sibling, not the element itself.
BThe button background turns red on hover as expected.
CThe button background turns red only when a sibling is hovered.
DA syntax error occurs because peer-hover cannot be used on the same element.
Attempts:
2 left
💡 Hint

Think about what peer-hover targets.