01 flex2个重要的概念

02 flex布局模型

03 flex相关属性

04 flex container相关属性

4.1 flex direction

不同的值会改变主轴的方向

4.2 flex-wrap

4.3 flex-flow

function getRandomColor() {
return `rgb(${Math.random()*255}, ${Math.random()*255}, ${Math.random()*255})`
} const itemEls = document.querySelectorAll(".item")
for (const item of itemEls) {
item.style.backgroundColor = getRandomColor()
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
display: flex;
flex-flow: row-reverse wrap;
width: 600px;
height: 600px;
background-color: orange;
} .item {
width: 200px;
height: 200px;
} </style>
</head>
<body> <div class="container">
<span class="item item1">1</span>
<span class="item item2">2</span>
<span class="item item3">3</span>
<span class="item item4">4</span>
</div>
<script src="./color.js"></script>
</body>
</html>

4.4 justify-content

4.5 align-item

4.6 align-content

05 flex-item的属性

5.1 order

改变flex-item的排布顺序

如下代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
display: flex;
width: 400px;
height: 400px;
background-color: orange;
} .box .item {
width: 100px;
height: 100px;
} .box .item1 {
background-color: aqua;
} .box .item2 {
background-color: pink;
} .box .item3 {
background-color: red;
}
</style>
</head>
<body>
<div class="box">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
</div>
</body>

效果如下图



设置order可以改变顺序

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
display: flex;
width: 400px;
height: 400px;
background-color: orange;
} .box .item {
width: 100px;
height: 100px;
} .box .item1 {
order: 5;
background-color: aqua;
} .box .item2 {
order: 4;
background-color: pink;
} .box .item3 {
order: 3;
background-color: red;
}
</style>
</head>
<body>
<div class="box">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
</div>
</body>
</html>

效果如下

5.2 align-self

5.3 flex-grow

该属性决定了flex-items如何拉伸

5.3.1 默认情况

默认值为0

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
display: flex;
width: 400px;
height: 400px;
background-color: orange;
} .box .item {
width: 100px;
height: 100px;
} .box .item1 {
background-color: aqua;
} .box .item2 {
background-color: pink;
} .box .item3 {
background-color: red;
}
</style>
</head>
<body>
<div class="box">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
</div>
</body>
</html>

5.3.2 给其中1个flex-item设置

效果如下

5.3.3 所有flex-items都设置

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
display: flex;
width: 400px;
height: 400px;
background-color: orange;
} .box .item {
flex-grow: 1;
width: 100px;
height: 100px;
} .box .item1 {
background-color: aqua;
} .box .item2 {
background-color: pink;
} .box .item3 {
background-color: red;
}
</style>
</head>
<body>
<div class="box">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
</div>
</body>
</html>

5.3.4 设置任意非负数

5.4 flex-shrink

该属性决定flex items如何收缩,默认是为1表示收缩

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
display: flex;
width: 400px;
height: 400px;
background-color: orange;
} .box .item {
width: 100px;
height: 100px;
} .box .item1 {
/* flex-shrink: 2; */
background-color: aqua;
} .box .item2 {
background-color: pink;
} .box .item3 {
background-color: red;
} .box .item4 {
background-color: purple;
} .box .item5 {
background-color: blue;
} .box .item6 {
background-color: red;
}
</style>
</head>
<body>
<div class="box">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
<div class="item item4">4</div>
<div class="item item5">5</div>
<div class="item item6">6</div>
</div>
</body>
</html>

设置压缩的值

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
display: flex;
width: 400px;
height: 400px;
background-color: orange;
} .box .item {
width: 100px;
height: 100px;
} .box .item1 {
flex-shrink: 2;
background-color: aqua;
} .box .item2 {
background-color: pink;
} .box .item3 {
background-color: red;
} .box .item4 {
background-color: purple;
} .box .item5 {
background-color: blue;
} .box .item6 {
background-color: red;
}
</style>
</head>
<body>
<div class="box">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
<div class="item item4">4</div>
<div class="item item5">5</div>
<div class="item item6">6</div>
</div>
</body>
</html>

06 缩写语法

07 flex布局解决对齐问题

第一种方法就是把距离都算出来,但是这种扩展性不强

第二种方法

color.js代码

function getRandomColor(){
return `rgb(${Math.random()*255}, ${Math.random()*255}, ${Math.random()*255})`
}
const itemEls = document.querySelectorAll(".item")
for (const item of itemEls){
item.style.backgroundColor = getRandomColor()
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
width: 500px;
/* height: 500px; */
background-color: orange;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.item {
width: 120px;
height: 120px;
background-color: red; }
</style>
</head>
<body>
<div class="container">
<div class="item item1">1</div>
<div class="item item2">2</div>
<div class="item item3">3</div>
<div class="item item4">4</div>
<div class="item item5">5</div>
<div class="item item6">6</div>
<div class="item item7">7</div>
<!-- <div class="item item8">8</div> -->
</div>
<script src="./color.js"></script>
</body>
</html>


这样不用通过计算,可以让其余行的元素都是均匀排布

13-flex的更多相关文章

  1. 2017.11.13 flex 布局相关问题

    一.今日任务:城市体验平台小程序的开发(由于数据还未完善,今天主要是 UI 布局的开发) 二.所遇问题 1. flex 布局问题: html: <view class="flex-sp ...

  2. 【转】【Flex】FLEX 学习网站分享

    [转:http://hi.baidu.com/tanghecaiyu/item/d662fbd7f5fbe02c38f6f764 ] FLEX 学习网站分享 http://blog.minidx.co ...

  3. 基于restful注解(spring4.0.2整合flex+blazeds+spring-mvc)<一>

    摘自: http://www.blogjava.net/liuguly/archive/2014/03/10/410824.html 参考官网:1.http://livedocs.adobe.com/ ...

  4. 轻轻松松学CSS:Flex布局

     Flex布局就是"弹性布局",它可以简便.完整.响应式地实现各种页面布局.引入弹性布局的目的,当页面需要适应不同的屏幕大小确保元素拥有恰当的布局方式,对一个容器中的子元素进行排列 ...

  5. Web前端面试题整合,持续更新【可以收藏】

    饭后闲来无事,把这几年带学生用的一些面试题整合一下,供上!拿走,不客气!应付一般公司的二面基本上是够用了.祝你早日拿到心仪的offer. css相关 1. 万能居中 1.margin: 0 auto; ...

  6. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十三)台风模块

    config.xml文件的配置如下: <widget label="台风" icon="assets/images/typhoon.png" config ...

  7. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十一)路径导航模块

    config.xml文件的配置如下: <widget label="路径导航" icon="assets/images/lujingdaohang.png" ...

  8. Eclipse开发环境设置(Maven+Spring MVC+Flex)

    1. 环境设置 1.1. Java环境设置 1)JAVA_HOME D:\GreenSoftware\Java\Java8X64\jdk1.8.0_91 2)PATH ;%JAVA_HOME%/bin ...

  9. CM12.1/13.0编译教程

    环境搭建 1.安装64位Ubuntu系统(实体安装.虚拟机安装均可) 注意:要求机器至少4G内存(虚拟机至少分配4G内存),硬盘至少100G空间(源码20G+,编译后整个目录约60~70G) 安装方法 ...

  10. FLEX各种特效集合

    http://www.noupe.com/adobe/flex-developers-toolbox-free-components-themes-and-tutorials.html经典中的经典 h ...

随机推荐

  1. 通俗易懂的生产环境Web应用架构介绍

    前言 看见一篇非常通俗易懂且适合新手阅读的Web应用架构文章,我将其手工翻译了出来,分享给大家. 也可以去阅读英文原文,标题为,贴出链接: https://stephenmann.io/post/wh ...

  2. 04.Java 流程控制

    1.用户交互 Scanner Scanner 对象:获取用户的输入 基本语法:Scanner s = new Scanner(System.in); 通过 Scanner 类的 next() 和 ne ...

  3. StarCoder2-Instruct: 完全透明和可自我对齐的代码生成

    指令微调 是一种技术,它能让大语言模型 (LLMs) 更好地理解和遵循人类的指令.但是,在编程任务中,大多数模型的微调都是基于人类编写的指令 (这需要很高的成本) 或者是由大型专有 LLMs 生成的指 ...

  4. CF933-Div3 大致思路+题解

    \(Rank\) A - Rudolf and the Ticket 纯水题 暴力枚举直接过 $code$ #include<bits/stdc++.h> #define fo(x,y,z ...

  5. 网络安全—模拟IP代理隐藏身份

    文章目录 网络拓扑 安装 使用 代理服务器设置 隐藏者设置 使用古老的ccproxy实现代理服务器,仅做实验用途,禁止做违法犯罪的事情,后果自负. 网络拓扑 均使用Windows Server 200 ...

  6. 【漏洞复现】蓝凌OA sysUiComponent 任意文件上传漏洞

    阅读须知 此文所提供的信息只为网络安全人员对自己所负责的网站.服务器等(包括但不限于)进行检测或维护参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作.利用此文所提供的信息而造成的直接 ...

  7. PasteSpider之接口的授权实现为什么不采用JWT方式

    PasteTemplate序列的接口权限控制使用的都是一套逻辑 包括不限于PasteSpider,PasteTimer,PasteTicker等 大致逻辑一致,具体的细节可能会根据项目做一些调整! 实 ...

  8. 🔥 FolkMQ v1.5.1 发布(“新式” 国产消息中间件)

    FolkMQ 是个"新式"的消息中间件.强调:"小而巧"."简而强". 功能简表 角色 功能 生产者(客户端) 发布普通消息.Qos0消息. ...

  9. 实战SQL优化(以MySQL深分页为例)

    1 准备表结构 CREATE TABLE `student` ( `id` int NOT NULL AUTO_INCREMENT, `user_no` varchar(50) CHARACTER S ...

  10. Linux下docker安装部署

    Linux下docker安装部署 环境说明 该文档安装环境为CentOS Linux release 7.9.2009,内核版本为3.10.0-1160.81.1.el7.x86_64 安装说明 安装 ...