当前位置: 首页 > news >正文

【前端基础】flex布局中使用`justify-content`后,最后一行的布局问题

flex布局中使用justify-content后,最后一行的布局问题

1、问题

  • 想要的结果:
    在这里插入图片描述

  • 使用 justify-content: space-between; 后实际结果:
    在这里插入图片描述

2、解决方法

  1. 在最后追加 nspan 元素。n 的值 = 列数 - 2
  2. 设置span元素的宽度 = flex item 的宽度

span 换成 i 元素也行。
在这里插入图片描述

<!DOCTYPE html>
<html><head><title>Document</title><style>.container {height: 500px;width: 500px;background-color: antiquewhite;margin: 0 auto;display: flex;flex-wrap: wrap;justify-content: space-between;}.item {width: 150px;height: 150px;background-color: aquamarine;}.item1 {background-color: orange;}.item2 {background-color: red;}.item3 {background-color: blueviolet;}.container span {width: 150px;}</style></head><body><div class="container"><div class="item item1">box1</div><div class="item item2">box2</div><div class="item item3">box3</div><div class="item item4">box4</div><div class="item item4">box5</div><div class="item item3">box6</div><div class="item item2">box7</div><div class="item item1">box8</div><!-- 列数- 2  = 追加的span个数 --><span></span></div></body>
</html>
http://www.lryc.cn/news/623463.html

相关文章:

  • ubuntu 24.04 安装
  • Android RxJava线程调度与性能优化指南
  • (一)前端面试(cookie/)
  • PostgreSQL导入mimic4
  • 数据结构代码分享-1 顺序表
  • 简单的 VSCode 设置
  • Oracle algorithm的含义
  • 基于Vue + Node能源采购系统的设计与实现/基于express的能源管理系统#node.js
  • Qt 5.5 的安装与配置(使用 VSCode编辑)
  • 【架构师从入门到进阶】第五章:DNSCDN网关优化思路——第十二节:网关安全-信息过滤
  • 基于多Agent的AFSIM复杂场景脚本生成技术(使用Claude Code)
  • 根号算法Ⅰ
  • 天地图应用篇: 增加缩放、比例尺控件
  • 24. 什么是不可变对象,好处是什么
  • 【Docker】搭建一款功能强大且免费的开源在线绘图工具 - draw.io
  • 云原生俱乐部-RH134知识点总结(2)
  • 62.不同路径
  • 【计算机网络面试】键入网址到网页显示期间,发生了什么?
  • 网络常识-DNS如何解析
  • 数据结构初阶(19)外排序·文件归并排序的实现
  • Ugit使用记录
  • 【自动化运维神器Ansible】template流程控制:for循环与if条件判断详解
  • Flink作业执行的第一步:DataFlow graph的构建
  • C11期作业18(07.12)
  • 栈与队列:数据结构中的双生子
  • 【JavaEE】多线程 -- 单例模式
  • [python学习记录2]变量
  • Maven 开发实践
  • PCA的一些实际应用
  • 详解flink java基础(一)