How to position the div popup dialog to the center of browser screen?

后端 未结 9 1744
Happy的楠姐
Happy的楠姐 2020-12-13 16:39

I need to position div popup to the center of browser screen ( no matter what size the screen is). And I want to keep the position as absolute as I don\'t want to move the p

9条回答
  •  再見小時候
    2020-12-13 17:02

    You can use CSS3 'transform':

    CSS:

    .popup-bck{
      background-color: rgba(102, 102, 102, .5);
      position: fixed;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      z-index: 10;
    }
    .popup-content-box{
      background-color: white;
      position: fixed;
      top: 50%;
      left: 50%;
      z-index: 11;
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    -o-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    }
    

    HTML:

    
    
    

    *so you don't have to use margin-left: -width/2 px;

提交回复
热议问题