Discover how to make popups that always look perfect and handle any amount of content smoothly!
Why Scrollable and centered modals in Bootsrap? - Purpose & Use Cases
Imagine you want to show a popup box on your website with important information. You try to make it appear in the middle of the screen and allow users to scroll if the content is too long.
If you try to do this by hand, you might struggle to keep the box perfectly centered on all screen sizes. Also, if the content is long, it might overflow outside the box or the page, making it hard to read or use.
Bootstrap's scrollable and centered modals handle these problems for you. They automatically center the popup and add scrolling inside the modal if the content is tall, so users can always see everything neatly.
<div style="position:absolute; top:50px; left:50px; height:400px; overflow:auto;">Long content here...</div><div class='modal fade' tabindex='-1'> <div class='modal-dialog modal-dialog-centered modal-dialog-scrollable'> <div class='modal-content'> <!-- content here --> </div> </div> </div>
You can easily create user-friendly popups that look great on any device and handle lots of content without extra work.
Think of a website showing terms and conditions in a popup. The text is long, but users can scroll inside the centered modal without losing context or page layout.
Manually centering and scrolling modals is tricky and error-prone.
Bootstrap provides built-in classes to center modals and make content scrollable.
This improves user experience and saves you time.
Practice
modal-dialog-scrollable do in a modal?Solution
Step 1: Understand the class purpose
The classmodal-dialog-scrollableis designed to allow the modal content area to scroll if the content is too long.Step 2: Compare with other classes
Unlikemodal-dialog-centeredwhich centers the modal, this class specifically controls scrolling inside the modal.Final Answer:
Makes the modal content scrollable inside the popup -> Option BQuick Check:
modal-dialog-scrollable = scrollable content [OK]
- Confusing scrollable with centered behavior
- Thinking it changes modal size
- Assuming it affects modal background
Solution
Step 1: Identify correct Bootstrap classes
Bootstrap usesmodal-dialog-scrollableandmodal-dialog-centeredas separate classes to add scroll and vertical centering.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.Final Answer:
<div class='modal-dialog modal-dialog-scrollable modal-dialog-centered'> -> Option AQuick Check:
Use both classes separated by space [OK]
- Using incorrect class names like 'scrollable' or 'centered'
- Combining classes into one word
- Missing one of the required classes
<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>Solution
Step 1: Analyze classes used
The modal uses bothmodal-dialog-scrollableandmodal-dialog-centeredclasses.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.Final Answer:
Modal content scrolls inside and modal is vertically centered on screen -> Option CQuick Check:
Both scrollable and centered classes active = scroll + center [OK]
- Assuming scroll disables centering
- Thinking content scrolls outside modal
- Confusing modal-body scrolling with page scrolling
modal-dialog-scrollable but the modal content is not scrolling. What is the likely mistake?Solution
Step 1: Check where the class is applied
Themodal-dialog-scrollableclass must be on themodal-dialogelement, not onmodal-contentor others.Step 2: Understand Bootstrap structure
If placed incorrectly, the scroll behavior won't activate because Bootstrap styles target the dialog container.Final Answer:
You placed modal-dialog-scrollable on the wrong element -> Option DQuick Check:
modal-dialog-scrollable must be on modal-dialog [OK]
- Adding scrollable to modal-content instead
- Confusing scrollable with centered class
- Forgetting to add modal-dialog class
Solution
Step 1: Identify required classes for scroll and center
Use bothmodal-dialog-scrollableandmodal-dialog-centeredon themodal-dialogelement.Step 2: Structure modal content properly
Insidemodal-content, includemodal-headerandmodal-footerwhich remain fixed, whilemodal-bodyscrolls.Step 3: Confirm Bootstrap default behavior
Bootstrap automatically keeps header and footer visible when using scrollable modals with this structure.Final Answer:
Use modal-dialog modal-dialog-scrollable modal-dialog-centered with modal-header, modal-body, and modal-footer inside modal-content -> Option AQuick Check:
Combine scrollable + centered + header/footer structure [OK]
- Adding scrollable to modal-content instead of modal-dialog
- Omitting modal-header or modal-footer
- Trying to fix header/footer with custom CSS unnecessarily
Ready to prove it?
Pass the test and this pattern moves unknown
