Please run the demo:
* {
margin:0;
padding:0;
}
.body {
font-family:Microsoft Yahei;
font-size:16px;
background-color:lightblue;
height: 200px;
width:200px;
line-height:2;
}
.body span {
background-color:pink;
}
.body img {
width:50px;
height:50px;
}
.body .img-wrapper {
background-color:orange;
}
.body .img-wrapper {
vertical-align:middle;
}
<div class="body">
<span class="wrapper">
words-g words-g words-g
<span class="img-wrapper">
<img src="https://avatars3.githubusercontent.com/u/23273077" alt="">
s
</span>
words-g words-g words-g
</span>
</div>
The point is that I set
.body .img-wrapper {
vertical-align:middle;
}
I was expecting the red lines in below picture is in the same line:
According to the specification,
Align the vertical midpoint of the box with the baseline of the parent box plus half the x-height of the parent.
So,I think:
- the vertical midpoint of the box is the first red line in the above picture and
- the baseline of the parent box plus half the x-height of the parent = the second red line
But it turns out I am wrong and I guess the key is x-height of the parent.So,I found this:
So, I thought x-height of the parent in this case is not the second red line because of the existence of the image.
So,my question is :
how much is the x-height of the parent in this case? Is it changed because of the existence of the image?
Or something else is wrong?
Please notice:
I just want to get the
x-height
value in this case,so I can understand thevertical-align
better.I am not asking for a specific solution.
Whatever thanks for your help!