gpt4 book ai didi

html - 图内 img 和 figcaption 之间不需要的空格

转载 作者:搜寻专家 更新时间:2023-10-31 21:55:27 24 4
gpt4 key购买 nike

为什么图中的 img 和 figcaption 之间有空白?img 和 figcaption 的 margin 和 padding 都是 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>

(我不是问如何删除这个空格,我是问为什么它在那里。)

最佳答案

因为 image 是一个 inline element 它在底部提供了额外的空间,你可以通过 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>

关于html - 图内 img 和 figcaption 之间不需要的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29160231/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com