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

js:flex弹性布局

目录

代码:

1、 flex-direction

2、flex-wrap

3、justify-content

4、align-items

5、align-content


代码:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>flex弹性布局测试</title><style>.containner{background-color: aqua;display: flex;flex-direction: row;height: 40rem;}.item{width: 40rem;font-size: 4rem;}</style>
</head>
<body><div class="containner"><div class="item" style="background-color: red;">1</div><div class="item" style="background-color: yellow;">2</div><div class="item" style="background-color: green;">3</div><div class="item" style="background-color: indigo;">4</div><div class="item" style="background-color: blue;">5</div><div class="item" style="background-color: salmon;">6</div></div></body>
</html>

给item设置一个宽度 原因是默认宽度太小

1、 flex-direction

 .containner{background-color: aqua;display: flex;flex-direction: row;height: 40rem;}

设置轴线:横轴 不轴内逆转

其他属性:

                                                   /* 1、设置横轴/纵轴  如果加reverse 就是轴内逆转*//*设置横轴*/flex-direction: row;/* 设置纵轴*//* flex-direction: column;*//* 设置横轴逆转 *//* flex-direction: row-reverse; *//* 设置纵轴逆转 *//* flex-direction: column-reverse; */

flex-direction: row-reverse; 横轴逆转

2、flex-wrap

换行/列 是否轴外逆转

  .containner{background-color: aqua;display: flex;flex-direction: row-reverse;height: 40rem;flex-wrap: wrap;}

换行

其他属性:

  /**2、是否换行/列 是否轴外逆转//* flex-wrap: wrap;  *//**换行 且纵向逆转*//* flex-wrap: wrap-reverse;  */

3、justify-content

第一轴如何排列(假设:设置的轴称为第一轴)

  .containner{background-color: aqua;display: flex;flex-direction: row;height: 40rem;flex-wrap: wrap;justify-content: center;}

中心对称排

其他属性:

                                              /* 3.轴线方向的对称方式 如中心对称 */justify-content: center;/* 起点对其 *//* justify-content: flex-start; *//*  终点对齐*//* justify-content: flex-end; *//* 轴线方向的排列方式 有间隔 *//* 两端中点对齐  两端间隔占0 中间间隔1*//* justify-content: space-between; *//* 区别两边间隔占0.5 中间间隔占1  *//* justify-content: space-around; *//* 所有间隔相等 *//* justify-content: space-evenly; */

4、align-items

第二轴是否拉伸以及如何排列 默认是拉伸   /* align-items: stretch; */

保持间距相等

    .containner{background-color: aqua;display: flex;flex-direction: row;height: 40rem;flex-wrap: wrap;justify-content: center;align-items: center;}

其他属性:

                                                         /* 4. 另一方向的对齐方式  默认是拉伸*//* align-items: center; *//* 不拉伸 中间对齐 *//* align-items: stretch; *//* 默认的拉伸 *//* align-items: flex-start; *//* align-items: flex-end; */

ps:相当于justify-content中间隔方式

 /* justify-content: space-between; */

            /* 区别两边间隔占0.5 中间间隔占1  */

            /* justify-content: space-around; */

            /* 所有间隔相等 */

            /* justify-content: space-evenly; */

5、align-content

如何对齐

     .containner{background-color: aqua;display: flex;flex-direction: row;height: 40rem;flex-wrap: wrap;justify-content: center;align-items: center;align-content: center;}

靠中间对称

其他属性:

                                                   /* 5.多个轴线 出现换行时 *//* align-content: center; *//* align-content: flex-start; *//* 纵向不拉伸 */}

ps:相当于justify-content中对齐方式

 justify-content: center;

            /* 起点对其 */

            /* justify-content: flex-start; */

            /*  终点对齐*/

            /* justify-content: flex-end; */

http://www.lryc.cn/news/365996.html

相关文章:

  • Pytorch常用函数用法归纳:创建tensor张量
  • WPF前端:一个纯Xaml的水平导航栏
  • 谷粒商城实战(033 业务-秒杀功能4-高并发问题解决方案sentinel 1)
  • STM32项目分享:智能家居(机智云)系统
  • 游戏盾之应用加速,何为应用加速
  • Java 基础面试题
  • Nginx 1.26.0 爆 HTTP/3 QUIC 漏洞,建议升级更新到 1.27.0
  • uniadmin引入iconfont报错
  • Vue3【三】 使用TS自己编写APP组件
  • 数字IC后端物理验证PV | TSMC 12nm Calibre Base Layer DRC案例解析
  • Echarts 在指定部分做文字标记
  • 如何发布自己的npm插件包
  • AI和机器人引领新一轮农业革命
  • 【Kubernetes】三证集齐 Kubernetes实现资源超卖(附镜像包)
  • 国产Sora免费体验-快手旗下可灵大模型发布
  • linux嵌入式设备测试wifi信号强度方法
  • 【名词解释】Unity的Inputfield组件及其使用示例
  • Android 安装调试 TelephonyProvider不生效
  • 【C++】STL中List的基本功能的模拟实现
  • C语言基础——函数
  • 《精通ChatGPT:从入门到大师的Prompt指南》第1章:认识ChatGPT
  • 智慧视觉怎么识别视频?智慧机器视觉是通过什么步骤识别视频的?
  • NineData蔡冬者参与编写墨天轮《2023年中国数据库行业年度分析报告》正式发布!
  • 帝国cms接入腾讯云人脸识别认证代码
  • 计算机网络-OSI七层参考模型与数据封装
  • [职场] 为什么不能加薪? #学习方法#知识分享#微信
  • [matlab]折线图之多条折线如何绘制实心圆作为标记点
  • HTML:认识HTML与基本语法的学习
  • 如何掌握 Java 正则表达式 的基本语法及在 Java 中的应用
  • 深度学习(三)