Make text height 100% of div?

前端 未结 6 1677
时光取名叫无心
时光取名叫无心 2020-12-03 21:35

I\'m trying to make the text 100% height of a div but it doesn\'t work.
It just becomes 100% of the body { font-size:?; }.

Is there an

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 21:58

    You can do it for single line texts using relative and absolute positions:

    Center text

    css:

    .div {
      height: 4%;
      position: relative:
      overflow: hidden;
    }
    
    .middle-center {
      position: absolute;
      top: 50%;
      bottom: 0;
      left: 0;
      right: 0;
      text-align: center;
      font-size: 13px;
      margin-top: -8px;
    } 
    

提交回复
热议问题