I am trying center text vertically and I use trick with translate.
HTML
<div class="first">
<div class="second">
<span>TESTING</span>
</div>
</div>
CSS
div.first > div.second {
border: 1px solid red;
height: 2em;
}
div.first > div.second > span{
position: relative;
top: 50%;
transform: translateY(-50%);
}
Why the text isn't vertical center?Fiddler
I notice when I change height css property to line-height text started center.
Can someone explain me why this working like that?