How to center div vertically inside of absolutely positioned parent div

前端 未结 9 1916
闹比i
闹比i 2020-12-02 04:48

I am trying to get blue container in the middle of pink one, however seems vertical-align: middle; doesn\'t do the job in that case.

9条回答
  •  孤街浪徒
    2020-12-02 05:12

    For only vertical center

        
    test

    I always do like this, it's a very short and easy code to center both horizontally and vertically

    .center{
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
    Hello Centered World!

提交回复
热议问题