position div center horizontal and vertical

后端 未结 2 524
温柔的废话
温柔的废话 2020-12-22 05:28

i would like to center a popup div how can i do that browser friendly????

this is the original a bit to the left.

相关标签:
2条回答
  • 2020-12-22 05:57

    I use this code to center an element in the center of the window viewport:

    html {
      display: table;
      table-layout: fixed;
      width: 100%; 
      height: 100%;
    }
    
    body {  
      display: table-cell;  
      width: 100%; 
      height: 100%;
      vertical-align: middle;
      margin:0;
    }
    
    #center {
      margin: auto;
    }
    

    You will find a full example at this link (Bredele CSS bundle). I think it should work for your popup.

    Olivier

    0 讨论(0)
  • 2020-12-22 06:12

    Not sure I understand which part you want to center, but assuming the whole thing:

    .popLayerWrapper {
       position: absolute;
       width: 40%;  /* could be anything */
       left: 50%;
       margin-left: -20%;  /* half of width */
       height: 40%;    /* again, could be anything */
       top: 50%;
       margin-top: -20%;  /* half of height */
    }
    
    0 讨论(0)
提交回复
热议问题