Vertically center text in a 100% height div?

后端 未结 13 601
傲寒
傲寒 2020-12-05 17:22

I am working with a div that is 100% of the parent divs height.

The div only contains a single line of text.

The div cannot have a fixed height.

So m

相关标签:
13条回答
  • 2020-12-05 18:02

    Modern solution - works in all browsers and IE9+

    caniuse - browser support.

    .v-center {
      position: relative;
      top: 50%;
      -webkit-transform: translateY(-50%);
          -ms-transform: translateY(-50%);
              transform: translateY(-50%);
    }
    

    Example: http://jsbin.com/rehovixufe/1/

    0 讨论(0)
提交回复
热议问题