Challenge - 5 Problems
Modal Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediate2:00remaining
What is the visible result of this modal code?
Given this Tailwind CSS modal snippet, what will the user see when the modal is open?
Tailwind
<div class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center"> <div class="bg-white p-6 rounded shadow-lg max-w-sm w-full"> <h2 class="text-xl font-bold mb-4">Modal Title</h2> <p class="mb-4">This is the modal content.</p> <button class="bg-blue-600 text-white px-4 py-2 rounded">Close</button> </div> </div>
Attempts:
2 left
💡 Hint
Look at the classes controlling position and background colors.
✗ Incorrect
The 'fixed inset-0' makes the overlay cover the entire screen. 'bg-black bg-opacity-50' creates a semi-transparent black background. 'flex items-center justify-center' centers the modal box. The modal box has white background, padding, rounded corners, and shadow.
❓ accessibility
intermediate2:00remaining
Which attribute improves accessibility for this modal?
You have a modal dialog. Which attribute should you add to the modal container to help screen readers identify it as a dialog?
Tailwind
<div class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center" role="dialog" aria-modal="true"> <div class="bg-white p-6 rounded shadow-lg max-w-sm w-full"> <h2 class="text-xl font-bold mb-4">Modal Title</h2> <p class="mb-4">This is the modal content.</p> <button class="bg-blue-600 text-white px-4 py-2 rounded">Close</button> </div> </div>
Attempts:
2 left
💡 Hint
Think about how screen readers know this is a modal dialog.
✗ Incorrect
Adding role="dialog" tells assistive tech this is a dialog. aria-modal="true" indicates the rest of the page is inert while modal is open, improving accessibility.
❓ selector
advanced2:00remaining
Which Tailwind selector targets the modal overlay only?
You want to style only the overlay background of a modal with Tailwind. The overlay has class 'fixed inset-0 bg-black bg-opacity-50'. Which selector targets only this overlay?
Attempts:
2 left
💡 Hint
Look for the classes that create the overlay background.
✗ Incorrect
The overlay uses classes fixed, inset-0, bg-black, and bg-opacity-50. Selecting all these classes together targets only the overlay element.
❓ layout
advanced2:00remaining
How to center modal content vertically and horizontally?
Which Tailwind utility classes center the modal box both vertically and horizontally inside the overlay?
Attempts:
2 left
💡 Hint
Think about flexbox centering utilities.
✗ Incorrect
Using 'flex' on the container with 'items-center' (vertical) and 'justify-center' (horizontal) centers the modal content perfectly.
🧠 Conceptual
expert2:00remaining
Why use aria-modal="true" in modals?
What is the main reason to add aria-modal="true" to a modal dialog container?
Attempts:
2 left
💡 Hint
Think about how screen readers treat the rest of the page when a modal is open.
✗ Incorrect
aria-modal="true" signals that the rest of the page is inactive, so screen readers focus only on the modal content, improving accessibility.