0
0
Bootsrapmarkup~20 mins

Scrollable and centered modals in Bootsrap - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modal Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What is the visual result of this Bootstrap modal code?
Given the following Bootstrap modal code, what will the user see when the modal is opened?
Bootsrap
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-dialog-centered">
    <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">
        <p>Line 1</p>
        <p>Line 2</p>
        <p>Line 3</p>
        <p>Line 4</p>
        <p>Line 5</p>
        <p>Line 6</p>
        <p>Line 7</p>
        <p>Line 8</p>
        <p>Line 9</p>
        <p>Line 10</p>
        <p>Line 11</p>
        <p>Line 12</p>
        <p>Line 13</p>
        <p>Line 14</p>
        <p>Line 15</p>
      </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 modal box appears centered vertically and horizontally with a scrollable body showing lines 1 to 15 inside the modal body area.
BA modal box appears at the top of the page with all lines 1 to 15 visible without scrolling.
CA modal box appears centered but the body is not scrollable, so only lines 1 to 5 are visible and the rest are cut off.
DA modal box appears at the bottom of the page with a fixed height and no scroll.
Attempts:
2 left
💡 Hint
Look at the classes on the modal-dialog div: modal-dialog-scrollable and modal-dialog-centered.
🧠 Conceptual
intermediate
1:30remaining
Which Bootstrap class makes the modal body scrollable?
You want a modal with a long content body that scrolls inside the modal instead of expanding the modal height. Which class should you add to the modal dialog?
Amodal-dialog-scrollable
Bmodal-dialog-centered
Cmodal-content-scroll
Dmodal-body-scroll
Attempts:
2 left
💡 Hint
The class is added to the modal-dialog div, not modal-content or modal-body.
📝 Syntax
advanced
2:00remaining
What error occurs if you forget the modal-dialog wrapper div inside a Bootstrap modal?
Consider this modal structure missing the modal-dialog div: <div class="modal fade" id="myModal" tabindex="-1" aria-hidden="true"> <div class="modal-content"> <div class="modal-header">...</div> <div class="modal-body">...</div> </div> </div> What happens when you try to open this modal?
AThe modal content is hidden and cannot be seen.
BBootstrap throws a JavaScript error and the modal does not open.
CThe modal opens normally with no visible difference.
DThe modal does not appear centered and the scrollable behavior does not work properly.
Attempts:
2 left
💡 Hint
Bootstrap requires a specific structure for modals to work correctly.
accessibility
advanced
1:30remaining
Which attribute improves accessibility for Bootstrap modals?
To make a Bootstrap modal accessible for screen readers, which attribute is essential on the modal container?
Aaria-hidden="true" on the modal dialog
Btabindex="0" on the modal body
Caria-labelledby with the id of the modal title element
Drole="button" on the modal footer buttons
Attempts:
2 left
💡 Hint
This attribute connects the modal container to its title for screen readers.
layout
expert
2:30remaining
How does Bootstrap center a modal vertically using Flexbox?
Bootstrap uses Flexbox to center modals vertically. Which CSS property on the .modal-dialog or its parent achieves vertical centering?
Adisplay: block; margin: auto; height: 100%;
Bdisplay: flex; align-items: center; min-height: 100vh;
Cposition: absolute; top: 50%; transform: translateY(-50%);
Ddisplay: grid; place-items: center center; height: 100vh;
Attempts:
2 left
💡 Hint
Bootstrap modal container uses flexbox with vertical alignment.