How to center a modal window on a page?

前端 未结 8 1688
太阳男子
太阳男子 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:34
    .modal
    {
    position: fixed;
    left: 50%;
    }
    
    0 讨论(0)
  • 2021-02-07 06:47

    when showing you modal you should put display:flex instead of block like most people usualy do. then :

    <div class="modal" id="modal">
     <div class="modal-content">
      What you want !
     </div>
    </div>
    

    and CSS :

    .modal {
     width: 100%;
     height: 100%;
    
     justify-content: center;
     align-items: center;
    }
    

    remember to put a close button in your modal-content because the other element on the screen won't be usable as the modal div covers all the screen size.

    0 讨论(0)
提交回复
热议问题