1

Any idea how I can vertically center text which can have one or two lines? More over, the text has it's line-height set. I've tried the following but it didn't work:

<div>
    <span>some text here</span>
</div>
<div>
    <span>some</span>
</div>

div {
    border: 1px solid;
    width: 70px;
    height: 50px;
    line-height: 50px;
}

span {
    display: inline-block;
    line-height: 14px;
}
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488

1 Answers1

2

You can always use display: table-cell trick with vertical-align: middle:

div {
    border: 1px solid;
    width: 70px;
    height: 50px;
    display: table;
}
span {
    display: table-cell;
    vertical-align: middle;
}
<div> <span>some text here</span>

</div>
<div> <span>some</span>

</div>
Alex Char
  • 32,879
  • 9
  • 49
  • 70