Bootstrap: Modal backdrop displays over modal in fixed container

Created on 11 Sep 2017  路  10Comments  路  Source: twbs/bootstrap

Having a "main-container" with

.app-container {
     position: fixed;
     top: 0;
     right: 0;
     bottom: 0;
     left: 0;
     overflow-y: auto;
 }

Makes the backdrop position above the modal, blocking everthing.

Plunker: https://plnkr.co/edit/8JvG9eje5FDssHykPwW8?p=preview
(With angular where modal.html and modal.ts has code for autoopening modal and app.ts and app.scss has template for main window)

Edit Seems like using .appendTo('body') when opening modal is a workaround, i.e $('#exampleModal').appendTo('body').modal('show');

css v4

Most helpful comment

Edit Seems like using .appendTo('body') when opening modal is a workaround, i.e $('#exampleModal').appendTo('body').modal('show');

Was the best solution so far. The button that triggers the modal must be changed to a click action with a function containing the lines above.

All 10 comments

This also happens in ReactJs, once the modal window and backdrop are visible, and you navigate off the current page using the back button, the modal window disappears but the backdrop stays, thereby blocking access to everything else.

This issue has marked as a won't/can't fix issue and a duplicate of #22801, #20433 or #3217.

Also in docs:

Modals use position: fixed, which can sometimes be a bit particular about its rendering. Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You鈥檒l likely run into issues when nesting a .modal within another fixed element.

Another workaround is add z-index: 1050 to your .app-container.

And related #25206. I believe #16432 will be reopen.

@ysds , tried it, but still did not work as desired. Was able to remove the backdrop using (".modal-backdrop").remove() in ("body").click(). But this is not an optimal solution since clicking on the body anytime would attempt to remove .modal-backdrop; (".modal-backdrop").click() did not generate an event , any suggestions on generating an on.click event from clicking the backdrop?.

Yes, the workaround in my previous comment will fix:

Makes the backdrop position above the modal, blocking everthing.

but your issue will not be fixed:

and you navigate off the current page using the back button, the modal window disappears but the backdrop stays,

well, I'm pretty sure, even if all the parent of the div.modal has position: static, this will happen very often.

just studied more, some other non-overlapping element is still set toposition:fixed, so still causing problems. it seems the only absolute way to prevent this problem is to add the modal element under body.

@ysds summarizes this nicely in his comment: https://github.com/twbs/bootstrap/issues/23916#issuecomment-364618947

Closing this.

Hey, i just realized i was getting this issue because i had another package installed (https://www.npmjs.com/package/bulma) that was overriding bootstrap styling.

Edit Seems like using .appendTo('body') when opening modal is a workaround, i.e $('#exampleModal').appendTo('body').modal('show');

Was the best solution so far. The button that triggers the modal must be changed to a click action with a function containing the lines above.

<script>
     $('#exampleModal').appendTo('body');
</script>

I added this directly after my modal, and the modal html was being loaded in via ajax, so as soon as my ajax html loaded, all my modals stacked nicely before the closing tag of the modal.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iklementiev picture iklementiev  路  3Comments

athimannil picture athimannil  路  3Comments

devdelimited picture devdelimited  路  3Comments

ghost picture ghost  路  3Comments

eddywashere picture eddywashere  路  3Comments