-2

Whey the vertical-align: middle is applied to outer text and not to the text inside div.code

.code {
display: inline-flex;
border: 3px solid black;
height: 2.2rem;
text-align: center;
vertical-align: middle;
}
<div>
  code
  <div class="code">380805</div>
</div>
Eugen Konkov
  • 15,716
  • 7
  • 69
  • 107

1 Answers1

1

You have to use align-items:center to center the content of .code class because you are using display:inline-flex

if you want to use verticle-align:middle , then you have to give display:table-cell to .code class

.code1 {
display: table-cell;
border: 3px solid black;
height: 2.2rem;
text-align: center;
vertical-align: middle;
}

.code {
display: inline-flex;
border: 3px solid black;
height: 2.2rem;
text-align: center;
align-items: center;
}
<div>
  code
  <div class="code">380805</div>
   <div class="code1">380805</div>
</div>
Saurabh Mistry
  • 8,903
  • 4
  • 33
  • 51
yjs
  • 672
  • 3
  • 11