Text line-height won't work with inline-block div container

后端 未结 1 1194
天涯浪人
天涯浪人 2021-01-19 02:55

Here is the jsfiddle. HTML:

Center with Red!

CSS:

相关标签:
1条回答
  • 2021-01-19 03:18

    You can simple add vertical-align: top to .div1:

    .main {
      height: 50px;
      width: 100%;
      background-color: #000000;
      text-align: center;
      color: #ffffff;
      line-height: 50px;
      font-size: 24px;
    }
    .div1 {
      display: inline-block;
      width: 50px;
      height: 50px;
      background-color: #ff0000;
      vertical-align: top;
    }
    <div class="main">
      <div class="div1"></div>
      Center with Red!
    </div>

    Edit after @chead24 comment.

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