.container {
  display: flex;
  justify-content: space-between;
}

.box {
  flex: 1;
}

解释:

  • 将容器设置为 flex 布局,通过 justify-content: space-between 属性使得子元素水平分布在容器中,左右两端与容器边缘对齐。
  • 将子元素设置为 flex: 1,即让它们均分容器的剩余空间。因为有 3 个子元素,所以它们会被平均分为 3 等份。
HTML 盒子平均三等分:使用 Flex 布局实现

原文地址: https://www.cveoy.top/t/topic/oglH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录