Performance: Modal sizes and positioning
This affects the page's rendering speed and visual stability when modals appear, impacting how quickly users see and interact with modal content.
<div class="modal fade" tabindex="-1"> <div class="modal-dialog modal-lg modal-dialog-centered"> <div class="modal-content"> <!-- content --> </div> </div> </div>
<div class="modal fade" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <!-- content --> </div> </div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Default modal with dynamic size | Moderate (modal + backdrop nodes) | Multiple reflows on open and resize | Medium paint cost due to layout shifts | [X] Bad |
| Modal with fixed size and centered positioning | Moderate (same nodes) | Single reflow on open | Lower paint cost, stable layout | [OK] Good |
modal-sm for small, modal-lg for large, and modal-xl for extra large modals.modal-sm is used to make the modal smaller than the default size.modal-dialog-centered on the modal-dialog element to vertically center the modal.modal-dialog div, not modal or modal-content.<div class="modal-dialog modal-xl">
<div class="modal-content">
<!-- Modal body -->
</div>
</div>modal-xl is applied to the modal-dialog div, which sets the modal to extra large size.A) <div class="modal-dialog modal-lg modal-dialog-centered"> B) <div class="modal-dialog modal-centered modal-lg"> C) <div class="modal-dialog modal-lg-centered"> D) <div class="modal-dialog modal-lg center-dialog">
modal-lg for large size and modal-dialog-centered for vertical centering.modal-dialog div. Other options use incorrect or non-existent classes.modal-dialog to achieve this?modal-sm, modal-lg, and modal-xl are not responsive by themselves and cannot be combined to change size at different screen widths.modal-dialog-centered for vertical centering and write custom CSS media queries to adjust modal width responsively.Pass the test and this pattern moves unknown