Vertically align div (no tables)

后端 未结 8 1291
孤街浪徒
孤街浪徒 2020-12-02 17:38

I can horizontally align a div and all the content looks nice. Looking to vertical align a div that does not contain any tables. I tried setting margin positions to some neg

8条回答
  •  时光取名叫无心
    2020-12-02 18:25

    CSS class to align a element in middle of the screen:

    .middle{
        position: absolute;
        top: 50%; /*50% from top*/
        left: 50%; /*50% from left*/ 
    
        /*remove 50% of element width and height to align the element center in the position*/
        transform: translateY(-50%) translateX(-50%); 
    }
    

    Now, add this class to HTML element

提交回复
热议问题