Positioning
element at center of screen

后端 未结 13 1400
死守一世寂寞
死守一世寂寞 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 18:59

    It will work for any object. Even if you don't know the size:

    .centered {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    

提交回复
热议问题