I was try to vertically align an image inside div accurately. And i saw a solution that is add font-size : 0
to the container box.It did work, but also confuse me a lot.
I read some blog and 10.8 Line height calculations: the line-height
and vertical-align
properties,learn something like line box
inline-level box
Leading and half-leading
.
but I still don't know how to use those conceptions to explain why the code snippet below can work right. Can someone explain the snippet step by step with the conceptions? Thank you!
* {
margin : 0;
padding : 0;
}
div {
background-color: #000;
line-height: 200px;
font-size: 0; /*what happened here*/
}
div img {
vertical-align: middle;
}
<div>
<img src="http://placehold.it/100x198/ffffff" alt="image">
</div>