css single or multiple line vertical align

后端 未结 8 2019
北荒
北荒 2020-11-28 21:04

I have a title that can have one or more lines.

How can I align the text vertically? If it was always one line I could just set the line-height to the container heig

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 21:22

    I like that kind of solution. I saw somewhere this trick in stackoverflow but do not remember where exactly. Very usefel! :)

    ul {
    background: #000; 
      padding-left: 0;
    }
    ul li {
      height: 130px;
      position: relative;
      -webkit-box-sizing: border-box;
              box-sizing: border-box;
      border-bottom: 3px solid #F7F7F7;
    }
    ul li:last-of-type {
      border-bottom: none;
    }
    ul li:after {
      color: #333;
      position: absolute;
      right: 35px;
      font-size: 40px;
      content: ">";
      top: 50%;
      margin-top: -24px;
      color: #FFDA00;
      -webkit-transition: 0.25s all ease;
      transition: 0.25s all ease;
    }
    ul li a {
      font-size: 35px;
      font-family: Arial;
      color: #fff;
      -webkit-box-sizing: border-box;
              box-sizing: border-box;
      padding-left: 40px;
      height: 100%;
      line-height: 38px;
      display: inline-block;
      width: 100%;
      text-align: left;
      text-decoration: none;
    }
    ul li a:before {
      display: inline-block;
      vertical-align: middle;
      content: " ";
      height: 100%;
    }
    ul li a span {
      display: inline-block;
      vertical-align: middle;
    }

提交回复
热议问题