0
0
Tailwindmarkup~20 mins

Modal and overlay patterns in Tailwind - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modal Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2: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>
AA centered white box with a shadow on a semi-transparent black background covering the entire screen.
BA white box in the top-left corner with no background overlay.
COnly a black screen with no visible modal content.
DA white box centered but without any shadow or background overlay.
Attempts:
2 left
💡 Hint
Look at the classes controlling position and background colors.
accessibility
intermediate
2: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>
Atabindex="-1" aria-hidden="true"
Baria-describedby="close-button"
Caria-live="polite" role="alert"
Drole="dialog" aria-modal="true"
Attempts:
2 left
💡 Hint
Think about how screen readers know this is a modal dialog.
selector
advanced
2: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?
A.modal > div
B.bg-white.p-6.rounded.shadow-lg
C.fixed.inset-0.bg-black.bg-opacity-50
D.flex.items-center.justify-center
Attempts:
2 left
💡 Hint
Look for the classes that create the overlay background.
layout
advanced
2:00remaining
How to center modal content vertically and horizontally?
Which Tailwind utility classes center the modal box both vertically and horizontally inside the overlay?
Agrid place-items-center
Bflex items-center justify-center
Cblock mx-auto my-auto
Dabsolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2
Attempts:
2 left
💡 Hint
Think about flexbox centering utilities.
🧠 Conceptual
expert
2:00remaining
Why use aria-modal="true" in modals?
What is the main reason to add aria-modal="true" to a modal dialog container?
AIt tells assistive technologies that the rest of the page is inert and only the modal content should be accessed.
BIt automatically traps keyboard focus inside the modal without extra scripting.
CIt makes the modal content visible on all screen sizes.
DIt disables scrolling on the page behind the modal.
Attempts:
2 left
💡 Hint
Think about how screen readers treat the rest of the page when a modal is open.