Vertically centering a div in body?

后端 未结 5 2111
灰色年华
灰色年华 2020-12-14 02:26

I have tried to center this vertically in body (not horizontally). Also, I do not want to specify heights or anything like that. I tried adding a wrapper with a

5条回答
  •  天涯浪人
    2020-12-14 03:09

    See this edited version of your jsFiddle.

    Basically, just wrap your content in

    , and add the following CSS:

    html, body {
        height: 100%;
    }
    .main {
        height: 100%;
        width: 100%;
        display: table;
    }
    .wrapper {
        display: table-cell;
        height: 100%;
        vertical-align: middle;
    }
    

提交回复
热议问题