Bird
Raised Fist0
Bootsrapmarkup~10 mins

Scrollable and centered modals in Bootsrap - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to make the modal vertically centered.

Bootsrap
<div class="modal-dialog [1]">
  <div class="modal-content">
    <div class="modal-header">
      <h5 class="modal-title">Centered Modal</h5>
      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
    </div>
    <div class="modal-body">
      <p>This modal is vertically centered.</p>
    </div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Amodal-dialog-centered
Bmodal-dialog-scrollable
Cmodal-content-centered
Dmodal-centered
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'modal-dialog-scrollable' instead of 'modal-dialog-centered'.
Adding 'modal-centered' which is not a valid Bootstrap class.
2fill in blank
medium

Complete the code to make the modal body scrollable when content is long.

Bootsrap
<div class="modal-dialog [1]">
  <div class="modal-content">
    <div class="modal-header">
      <h5 class="modal-title">Scrollable Modal</h5>
      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
    </div>
    <div class="modal-body">
      <p>Lots of content here...</p>
      <!-- Imagine many paragraphs here -->
    </div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Amodal-scrollable
Bmodal-dialog-scrollable
Cmodal-body-scrollable
Dmodal-dialog-centered
Attempts:
3 left
💡 Hint
Common Mistakes
Adding scrollable class to modal-body instead of modal-dialog.
Using 'modal-scrollable' which is not a Bootstrap class.
3fill in blank
hard

Fix the error in the modal code to make it scrollable and centered.

Bootsrap
<div class="modal-dialog [1] [2]">
  <div class="modal-content">
    <div class="modal-header">
      <h5 class="modal-title">Scrollable & Centered Modal</h5>
      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
    </div>
    <div class="modal-body">
      <p>Content that requires scrolling...</p>
    </div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Amodal-dialog-scrollable
Bmodal-dialog-centered
Cmodal-content-scrollable
Dmodal-scrollable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'modal-content-scrollable' which is not a valid class.
Adding scrollable class to modal-content instead of modal-dialog.
4fill in blank
hard

Fill both blanks to create a scrollable and vertically centered modal dialog.

Bootsrap
<div class="modal-dialog [1] [2]">
  <div class="modal-content">
    <div class="modal-header">
      <h5 class="modal-title">Modal Title</h5>
      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
    </div>
    <div class="modal-body">
      <p>Scrollable content here...</p>
    </div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Amodal-dialog-scrollable
Bmodal-dialog-centered
Cmodal-content-scrollable
Dmodal-scrollable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'modal-content-scrollable' which is invalid.
Adding scrollable class to modal-content instead of modal-dialog.
5fill in blank
hard

Fill all three blanks to create a scrollable, vertically centered modal with a proper header and close button.

Bootsrap
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog [1] [2]">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">[3]</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <p>Scrollable and centered modal content.</p>
      </div>
    </div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Amodal-dialog-scrollable
Bmodal-dialog-centered
CScrollable & Centered Modal
Dmodal-content-scrollable
Attempts:
3 left
💡 Hint
Common Mistakes
Putting scrollable class on modal-content instead of modal-dialog.
Leaving the modal title blank or using invalid class names.

Practice

(1/5)
1. What does the Bootstrap class modal-dialog-scrollable do in a modal?
easy
A. Disables modal animations
B. Makes the modal content scrollable inside the popup
C. Changes the modal background color
D. Centers the modal vertically on the screen

Solution

  1. Step 1: Understand the class purpose

    The class modal-dialog-scrollable is designed to allow the modal content area to scroll if the content is too long.
  2. Step 2: Compare with other classes

    Unlike modal-dialog-centered which centers the modal, this class specifically controls scrolling inside the modal.
  3. Final Answer:

    Makes the modal content scrollable inside the popup -> Option B
  4. Quick Check:

    modal-dialog-scrollable = scrollable content [OK]
Hint: Scrollable modals use modal-dialog-scrollable class [OK]
Common Mistakes:
  • Confusing scrollable with centered behavior
  • Thinking it changes modal size
  • Assuming it affects modal background
2. Which is the correct way to add both scrollable and vertically centered behavior to a Bootstrap modal dialog?
easy
A. <div class='modal-dialog modal-dialog-scrollable modal-dialog-centered'>
B. <div class='modal-dialog scrollable-centered'>
C. <div class='modal-dialog scrollable centered'>
D. <div class='modal-dialog scrollable centered-modal'>

Solution

  1. Step 1: Identify correct Bootstrap classes

    Bootstrap uses modal-dialog-scrollable and modal-dialog-centered as separate classes to add scroll and vertical centering.
  2. Step 2: Check syntax for multiple classes

    Multiple classes are added separated by spaces inside the class attribute, so both classes must be included exactly as documented.
  3. Final Answer:

    <div class='modal-dialog modal-dialog-scrollable modal-dialog-centered'> -> Option A
  4. Quick Check:

    Use both classes separated by space [OK]
Hint: Use both classes separated by spaces inside class attribute [OK]
Common Mistakes:
  • Using incorrect class names like 'scrollable' or 'centered'
  • Combining classes into one word
  • Missing one of the required classes
3. Given this modal HTML snippet, what will be the visual effect?
<div class='modal-dialog modal-dialog-scrollable modal-dialog-centered'>
  <div class='modal-content'>
    <div class='modal-body'>
      <p>Very long content here...</p>
    </div>
  </div>
</div>
medium
A. Modal is centered but content does not scroll
B. Modal content scrolls but modal is aligned to top
C. Modal content scrolls inside and modal is vertically centered on screen
D. Modal neither scrolls nor centers vertically

Solution

  1. Step 1: Analyze classes used

    The modal uses both modal-dialog-scrollable and modal-dialog-centered classes.
  2. Step 2: Understand combined effect

    These classes together make the modal vertically centered and allow the modal body content to scroll if it is long.
  3. Final Answer:

    Modal content scrolls inside and modal is vertically centered on screen -> Option C
  4. Quick Check:

    Both scrollable and centered classes active = scroll + center [OK]
Hint: Both classes together scroll content and center modal [OK]
Common Mistakes:
  • Assuming scroll disables centering
  • Thinking content scrolls outside modal
  • Confusing modal-body scrolling with page scrolling
4. You added modal-dialog-scrollable but the modal content is not scrolling. What is the likely mistake?
medium
A. You forgot to add modal-dialog-centered
B. You must add scrollable class instead
C. You need to add overflow-auto to modal-content
D. You placed modal-dialog-scrollable on the wrong element

Solution

  1. Step 1: Check where the class is applied

    The modal-dialog-scrollable class must be on the modal-dialog element, not on modal-content or others.
  2. Step 2: Understand Bootstrap structure

    If placed incorrectly, the scroll behavior won't activate because Bootstrap styles target the dialog container.
  3. Final Answer:

    You placed modal-dialog-scrollable on the wrong element -> Option D
  4. Quick Check:

    modal-dialog-scrollable must be on modal-dialog [OK]
Hint: Apply scrollable class only on modal-dialog div [OK]
Common Mistakes:
  • Adding scrollable to modal-content instead
  • Confusing scrollable with centered class
  • Forgetting to add modal-dialog class
5. You want a modal that is vertically centered, scrollable, and also has a fixed header and footer that stay visible while the body scrolls. Which Bootstrap structure and classes should you use?
hard
A. Use modal-dialog modal-dialog-scrollable modal-dialog-centered with modal-header, modal-body, and modal-footer inside modal-content
B. Use modal-dialog modal-dialog-centered only and add custom CSS for scrolling
C. Use modal-dialog-scrollable on modal-content and add fixed position to header/footer
D. Use modal-dialog modal-dialog-scrollable but omit modal-header and modal-footer

Solution

  1. Step 1: Identify required classes for scroll and center

    Use both modal-dialog-scrollable and modal-dialog-centered on the modal-dialog element.
  2. Step 2: Structure modal content properly

    Inside modal-content, include modal-header and modal-footer which remain fixed, while modal-body scrolls.
  3. Step 3: Confirm Bootstrap default behavior

    Bootstrap automatically keeps header and footer visible when using scrollable modals with this structure.
  4. Final Answer:

    Use modal-dialog modal-dialog-scrollable modal-dialog-centered with modal-header, modal-body, and modal-footer inside modal-content -> Option A
  5. Quick Check:

    Combine scrollable + centered + header/footer structure [OK]
Hint: Use both classes on modal-dialog and include header/footer inside modal-content [OK]
Common Mistakes:
  • Adding scrollable to modal-content instead of modal-dialog
  • Omitting modal-header or modal-footer
  • Trying to fix header/footer with custom CSS unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard