0
0
Bootsrapmarkup~20 mins

Modal structure and triggers in Bootsrap - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modal Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2: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>
AA popup window appears with the title 'Modal title', body text 'This is the modal body content.', and two buttons labeled 'Close' and 'Save changes'.
BNothing happens because the modal is missing the 'show' class.
CThe page navigates to a new URL because the button is a link.
DAn error message appears because the modal ID does not match the button's data-bs-target.
Attempts:
2 left
💡 Hint
Look at the button's data attributes and the modal's ID to understand the trigger.
🧠 Conceptual
intermediate
1: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?
Adata-toggle="modal" href="#myModal"
Bdata-bs-toggle="modal" data-bs-target="#myModal"
Conclick="openModal('myModal')"
Daria-controls="myModal"
Attempts:
2 left
💡 Hint
Bootstrap 5 uses 'data-bs-' prefix for JavaScript behavior.
📝 Syntax
advanced
2:00remaining
What error occurs if the modal's HTML is missing the 'modal-dialog' div?
Consider this modal HTML missing the
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>
AThe modal content is hidden and cannot be seen.
BBootstrap throws a JavaScript error and modal does not open.
CThe modal opens normally with no visible difference.
DThe modal appears but content is not centered or styled properly.
Attempts:
2 left
💡 Hint
The 'modal-dialog' class controls modal positioning and styling.
accessibility
advanced
1: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?
Aaria-labelledby="modalTitleId"
Baria-describedby="modalTitleId"
Caria-hidden="false"
Drole="dialog"
Attempts:
2 left
💡 Hint
This attribute points to the element that labels the modal.
selector
expert
2: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?
A.modal-dialog.active
B.modal-dialog:visible
C.modal.show .modal-dialog
D.modal[aria-hidden="false"] .modal-dialog
Attempts:
2 left
💡 Hint
Bootstrap adds the 'show' class to visible modals.