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

flex布局,换行的元素上下设置间距

要生成的效果图如下:
在这里插入图片描述

 display:flexflex-direction: row;flex-wrap: wrap;

当我们使用弹性盒子布局后,默认元素是没有外边距的,紧挨着样式就有点丑,如果想使换行后,元素的外边距有个距离,可以用如下方法解决

解决办法
1.父元素定高的情况下,直接使用 align-content: space-between;

       ul{list-style: none;display: flex;height: 614px;flex-direction: row;flex-wrap: wrap;justify-content: space-between;align-content: space-between;}ul li{width: 234px;height: 300px;background-color: rgb(255, 2, 192);}

2.父元素不定高的情况下
1)设置需要更改间距的元素(li)的margin-bottom:14px,然后用父容器(ul)的margin-bottom: -14px;来抵消。

       ul{list-style: none;display: flex;flex-direction: row;flex-wrap: wrap;margin-bottom: -14px;justify-content: space-between;align-content: space-between;}li{margin-bottom: 14px;}ul li{display: flex;width: 234px;height: 300px;background-color: rgb(255, 2, 192);}

2) 设置需要更改间距的元素(li)的margin-bottom:14px;然后使用结构伪类选择器设置最后的几个元素margin-bottom: 0 ;

      ul{list-style: none;display: flex;flex-direction: row;flex-wrap: wrap;justify-content: space-between;align-content: space-between;}li{margin-bottom: 14px;}li:nth-child(n+5){margin-top: 0;}ul li{display: flex;width: 234px;height: 300px;background-color: rgb(255, 2, 192);}
http://www.lryc.cn/news/258769.html

相关文章:

  • 【智能家居】八、监控摄像采集、人脸识别比对进行开门功能点
  • golang的文件操作
  • 数据库版本管理框架-Flyway(从入门到精通)
  • 外网访问内网服务器使用教程
  • C# Dictionary 利用 ContainsValue 查询指定值是否已经存在
  • 招不到人?用C语言采集系统批量采集简历
  • HXDSP2441-Demo板
  • 静态路由的原理和配置
  • Ubuntu20.04降低linux版本到5.4.0-26-generic
  • C++ 类型萃取
  • 【JVM从入门到实战】(四)类的生命周期
  • 2023年度美食关键词-葱油花卷
  • 「Verilog学习笔记」简易秒表
  • 《每天一个Linux命令》 -- (12) file命令
  • 如何使用ArcGIS Pro制作类似CAD的尺寸注记
  • Go语言bufio包的使用
  • 计算机网络之IP篇
  • Java中JDK类库常用的6种设计模式
  • C++ 用法全面剖析
  • 数据库结构
  • 什么是HTML以及超链接,特殊符号转义的简单使用
  • 汽车销售技巧培训应该学习哪些内容
  • 机器学习---Adaboost算法
  • Java网络编程,使用UDP实现TCP(三), 基本实现四次挥手
  • “百里挑一”AI原生应用亮相,百度智能云千帆AI加速器首个Demo Day来了!
  • PyTorch深度学习实战(25)——自编码器
  • 靠谱的车- 华为OD统一考试(C卷)
  • Apache Flink(十一):Flink集群部署-Standalone集群部署
  • vue的组件传值
  • ue5材质预览界面ue 变黑