CSS: Responsive way to center a fluid div (without px width) while limiting the maximum width?

前端 未结 6 896
Happy的楠姐
Happy的楠姐 2020-12-04 12:54

I\'ve seen a million questions about how to center a block element and there seem to be a couple popular ways to do it, but they all rely on fixed pixels widths. Then either

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 13:20

    EDIT :
    http://codepen.io/gcyrillus/pen/daCyu So for a popup, you have to use position:fixed , display:table property and max-width with em or rem values :)
    with this CSS basis :

    #popup {
      position:fixed;
      width:100%;
      height:100%;
      display:table;
      pointer-events:none;
    }
    #popup > div {
      display:table-cell;
      vertical-align:middle;
    }
    #popup p {
      width:80%;
      max-width:20em;
      margin:auto;
      pointer-events:auto;
    }
    

提交回复
热议问题