Recall & Review
beginner
What is the
peer modifier in Tailwind CSS?The
peer modifier lets you style an element based on the state of a sibling element that has the peer class. It helps create interactive UI without JavaScript.Click to reveal answer
beginner
How do you use
peer-hover in Tailwind CSS?Add <code>peer</code> class to one element and <code>peer-hover:</code> prefix to a sibling's class. The sibling changes style when the peer is hovered.Click to reveal answer
intermediate
Why use
peer modifier instead of JavaScript for sibling state changes?Using
peer keeps styling in CSS, making code simpler, faster, and easier to maintain. It also improves accessibility and performance.Click to reveal answer
beginner
Example: What does this code do?
<input type="checkbox" class="peer" />
<label class="peer-checked:text-blue-600">Check me</label>
When the checkbox is checked, the label text color changes to blue. The label reacts to the checkbox state using
peer-checked.Click to reveal answer
intermediate
Can
peer modifier work with any sibling element?Yes, as long as the sibling has the
peer class, you can style other siblings based on its state using peer-* variants.Click to reveal answer
What does the
peer class do in Tailwind CSS?✗ Incorrect
The
peer class marks an element so sibling elements can react to its state using peer-* variants.Which prefix would you use to style a sibling when the peer is focused?
✗ Incorrect
Use
peer-focus: to style siblings when the peer element is focused.If an input has class
peer, how do you change a sibling's text color on input checked state?✗ Incorrect
The sibling uses
peer-checked: to react to the peer input's checked state.Can
peer modifier be used to style parent elements?✗ Incorrect
peer modifier only works for sibling elements, not parents.What is a benefit of using
peer modifier over JavaScript for sibling state styling?✗ Incorrect
Using
peer keeps styling in CSS, making code simpler and faster without extra scripts.Explain how the
peer modifier works in Tailwind CSS and give a simple example.Think about how one element's state can change another sibling's style.
You got /3 concepts.
Describe a real-life scenario where using the
peer modifier improves user experience without JavaScript.Consider checkboxes or toggles that change label styles.
You got /3 concepts.