Why there's white space between an img and figcaption inside figure? margin and padding of both img and figcaption are 0.
img {
width: 200px;
}
figcaption {
background-color: hsla(0, 0%, 0%, .5);
}
<figure>
<img src="https://www.gravatar.com/avatar/61af86922698a8cd422f77ae2343d2a5?s=48&d=identicon&r=PG&f=1" />
<figcaption>Hello</figcaption>
</figure>
(I'm not asking how to remove this space, I'm asking why it's there.)
As image
is a inline element
it gives extra space at the bottom you can fix it by giving vertical-align
img {
width: 200px;
vertical-align: middle;
}
figcaption {
background-color: hsla(0, 0%, 0%, .5);
}
<figure>
<img src="https://www.gravatar.com/avatar/61af86922698a8cd422f77ae2343d2a5?s=48&d=identicon&r=PG&f=1" />
<figcaption>Hello</figcaption>
</figure>
All you need is add a display: block in img tag.
img {
width: 200px;
background-color: hsla(0, 0%, 0%, .5);
display: block;
}
<figure>
<img src="https://www.google.com/images/srpr/logo11w.png" />
<figcaption>Hello</figcaption>
</figure>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With