You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Flex项改为figure元素后无法去除项间空白的问题

解决Flexbox中figure元素导致的空白问题

你遇到的空白是因为浏览器默认给<figure>元素设置了外边距(margin),这个默认样式会让flex容器里的figure项之间产生空隙。

只需要给figure元素清除默认外边距就能解决:

figure {
  margin: 0;
}

把这段代码添加到你的CSS里,flex项之间的空白就会消失。

修改后的完整CSS代码如下:

.container {
  display: flex;
  align-items: center;
  justify-content: center;
}

img {
  max-width: 25px;
}

figcaption {
  font-size: 10px;
  text-align: center
}

.ballon {
  display: flex;
  flex-flow: row wrap;
  max-width: 450px;
}

figure {
  margin: 0;
}

内容的提问来源于stack exchange,提问作者dawsboss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 16:10:33