Positioning
element at center of screen

后端 未结 13 1403
死守一世寂寞
死守一世寂寞 2020-11-28 18:34

I want to position a

(or a ) element at the center of the screen irrespective of screen size. In other words, the space le
13条回答
  •  再見小時候
    2020-11-28 19:19

    Set the width and height and you're good.

    div {
      position: absolute;
      margin: auto;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      width: 200px;
      height: 200px;
    }
    

    If you want the element dimensions to be flexible (and don't care about legacy browsers), go with XwipeoutX's answer.

提交回复
热议问题