How to center a modal window on a page?

前端 未结 8 1682
太阳男子
太阳男子 2021-02-07 05:43

I am trying center a modal window in the browser page. I just want to center it, so that it should be responsive for all the screens.

8条回答
  •  后悔当初
    2021-02-07 06:23

    Tried almost all CSS options, but finally something worked : jQuery

    setInterval(function()
         {
             if($('#myModal').is(':visible')===true)
             {
                 $("body").addClass("modal-open");
                 $('#myModal').css({"display":"flex"});
             }
             else
             {
                 $("body").removeClass("modal-open");
                 $('#myModal').css({"display":"none"});
             }
    
         },200);
    

    This is basic bug from Bootstrap regarding the adding/removal of class modal-open to the body tag which is being discussed over the years but no working solution till date.

提交回复
热议问题