Positioning
element at center of screen

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

    The easy way, if you have a fixed width and height:

    #divElement{
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: -50px;
        margin-left: -50px;
        width: 100px;
        height: 100px;
    }​
    

    Please don't use inline styles! Here is a working example http://jsfiddle.net/S5bKq/.

提交回复
热议问题