Challenge - 5 Problems
Modal Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediate2:00remaining
What is the visible result when this Bootstrap modal trigger is clicked?
Given the following HTML snippet using Bootstrap 5, what will the user see after clicking the button?
Bootsrap
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">Open Modal</button> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> This is the modal body content. </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
Attempts:
2 left
💡 Hint
Look at the button's data attributes and the modal's ID to understand the trigger.
✗ Incorrect
The button uses data-bs-toggle="modal" and data-bs-target="#exampleModal" which triggers the modal with ID 'exampleModal' to appear. The modal content includes a header, body, and footer with buttons. The modal is hidden initially but appears on button click.
🧠 Conceptual
intermediate1:30remaining
Which attribute correctly links a button to open a Bootstrap modal?
You want a button to open a modal with ID 'myModal'. Which attribute and value should you add to the button?
Attempts:
2 left
💡 Hint
Bootstrap 5 uses 'data-bs-' prefix for JavaScript behavior.
✗ Incorrect
In Bootstrap 5, to trigger a modal, the button needs data-bs-toggle="modal" and data-bs-target="#modalID". The other options either use old syntax or are unrelated.
📝 Syntax
advanced2:00remaining
What error occurs if the modal's HTML is missing the 'modal-dialog' div?
Consider this modal HTML missing the
wrapper. What happens when the modal is triggered?
Bootsrap
<div class="modal fade" id="testModal" tabindex="-1" aria-hidden="true"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Title</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body">Content</div> </div> </div>
Attempts:
2 left
💡 Hint
The 'modal-dialog' class controls modal positioning and styling.
✗ Incorrect
The 'modal-dialog' div is required to center and style the modal content. Without it, the modal content appears but is not positioned or styled correctly, causing layout issues but no JS errors.
❓ accessibility
advanced1:30remaining
Which attribute improves accessibility by linking modal title to the modal dialog?
In Bootstrap modals, which attribute on the modal container connects the modal title for screen readers?
Attempts:
2 left
💡 Hint
This attribute points to the element that labels the modal.
✗ Incorrect
The 'aria-labelledby' attribute on the modal container references the ID of the modal's title element, helping screen readers announce the modal's title. 'aria-describedby' is for description, 'role' defines the element type but does not link the title.
❓ selector
expert2:30remaining
Which CSS selector targets only the visible Bootstrap modal dialog?
You want to style only the modal dialog that is currently visible (shown) in Bootstrap 5. Which CSS selector correctly selects it?
Attempts:
2 left
💡 Hint
Bootstrap adds the 'show' class to visible modals.
✗ Incorrect
Bootstrap adds the 'show' class to the modal container when visible. The selector '.modal.show .modal-dialog' targets the dialog inside a visible modal. ':visible' is not a valid CSS selector, '.active' is not used by Bootstrap for modals, and 'aria-hidden' is a string attribute but not reliable for CSS selection.