Positioning
element at center of screen

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

    If you have a fixed div just absolute position it at 50% from the top and 50% left and negative margin top and left of half the height and width respectively. Adjust to your needs:

    div {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 500px;
        height: 300px;
        margin-left: -250px;
        margin-top: -150px;
    }
    

提交回复
热议问题