1. 设置弹性元素的增长因子(flex-grow)
设置项目的放大比例, 默认为0: 不放大,哪怕轴上有剩余空间
CSS语法: flex-grow: number|initial|inherit;
属性值:
- number:一个数字,规定项目将相对于其他灵活的项目进行扩展的量。默认值是 0
- initial:设置该属性为它的默认值
inherit:从父元素继承该属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>设置弹性元素的增长因子</title>
<style>
/*弹性容器通用样式*/
.container {
border: 2px dashed greenyellow;
margin: 15px;
background-color: grey;
width: 550px;
}
/*弹性元素通用样式*/
.item {
box-sizing: border-box;
border: 1px solid red;
padding: 20px;
background-color: lightpink;
width: 100px;
}
/*块级弹性容器*/
.flex {
display: flex;
}
/*默认值为0*/
.demo01 > .item {
flex-grow: 0;
}
/*第一个与第三个增长量的属性可以省略*/
.demo02 > .item:first-of-type {
/*flex-grow: 0;*/
}
.demo02 > .item:nth-of-type(2) {
flex-grow: 1;
}
.demo02 > .item:last-of-type {
/*flex-grow: 0;*/
}
.demo03 > .item:first-of-type {
flex-grow: 1;
}
.demo03 > .item:nth-of-type(2) {
flex-grow: 2;
}
.demo03 > .item:last-of-type {
flex-grow: 3;
}
/*
计算步骤:
1. 获取基本变量
1.1 可分配空间:550px - (100px + 100px +100px) = 250px
1.2 增长因子:第一个: 1, 第二个: 2, 第三个: 3
1.3 增长因子之和: 1 + 2 + 3 = 6
2. 计算增长比例
2.1 计算公式:增长比例 = 增长因子 / 增长因子之和
2.2 第一个元素:1 / 6 = 0.167
2.3 第二个元素:2 / 6 = 0.333
2.4 第三个元素:3 / 6 = 0.5
3. 计算每个元素的增长量
3.1 第一个元素:250px * 0.167 = 41.75px
3.2 第二个元素:250px * 0.333 = 83.25px
3.3 第三个元素:250px * 0.5 = 125px
4. 计算每个元素的最终宽度
4.1 第一个元素:100px + 41.75px = 141.75px
4.2 第二个元素:100px + 83.25px = 183.25px
4.3 第三个元素:100px + 125px = 225px
*/
.demo04 > .item:first-of-type {
flex-grow: 0.3;
}
.demo04 > .item:nth-of-type(2) {
flex-grow: 0.1;
}
.demo04 > .item:last-of-type {
flex-grow: 0.6;
}
.demo05 > .item:first-of-type {
width: 75px;
flex-grow: 2;
}
.demo05 > .item:nth-of-type(2) {
width: 150px;
flex-grow: 3;
}
.demo05 > .item:last-of-type {
width: 165px;
flex-grow: 7;
}
/*
计算步骤:
1. 获取基本变量
1.1 可分配空间:550px - (75px + 150px + 165px) = 160px
1.2 增长因子:第一个: 2, 第二个: 3, 第三个: 7
1.3 增长因子之和: 2 + 3 + 7 = 12
2. 计算增长比例
2.1 计算公式:增长比例 = 增长因子 / 增长因子之和
2.2 第一个元素:2 / 12 = 0.167
2.3 第二个元素:3 / 12 = 0.25
2.4 第三个元素:7 / 12 = 0.583
3. 计算每个元素的增长量
3.1 第一个元素:160px * 0.167 = 26.72px
3.2 第二个元素:160px * 0.25 = 40px
3.3 第三个元素:160px * 0.583 = 93.28px
4. 计算每个元素的最终宽度
4.1 第一个元素:75px + 26.72px = 101.72px
4.2 第二个元素:150px + 40px = 190px
4.3 第三个元素:165px + 93.28px = 258.28px
*/
</style>
</head>
<body>
<h1>设置弹性元素的增长因子</h1>
<h3>1. 所有弹性元素不增长,以原始宽度显示,增长因子为:0(默认)</h3>
<div class="container flex demo01">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>2. 将全部的剩余空间分配给指定弹性元素</h3>
<div class="container flex demo02">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>3. 全部剩余空间按增长因子在不同弹性元素间分配</h3>
<div class="container flex demo03">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>4. 增长因子支持小数, 因为是按增长比例分配</h3>
<div class="container flex demo04">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>5. 每个弹性元素宽度不同时, 同样适用以上分配规律</h3>
<div class="container flex demo05">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
</body>
</html>
2. 设置弹性元素的缩减因子(flex-shrink)
设置了项目的缩小比例,默认为1, 即空间不足时, 自动缩小填充
CSS语法:flex-shrink: number|initial|inherit;
属性值:- number:一个数字,规定项目将相对于其他灵活的项目进行收缩的量。默认值是 1
- initial:设置该属性为它的默认值
- inherit:从父元素继承该属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>设置弹性元素的缩减因子</title>
<style>
/*弹性容器通用样式*/
.container {
border: 2px dashed greenyellow;
margin: 15px;
background-color: grey;
width: 550px;
}
/*弹性元素通用样式*/
.item {
box-sizing: border-box;
border: 1px solid red;
padding: 20px;
background-color: lightpink;
width: 250px;
}
/*块级弹性容器*/
.flex {
display: flex;
}
/*所有元素不缩减,以原始宽度显示*/
/*设置缩减因子为:0*/
.demo01 > .item {
flex-shrink: 0;
}
/*
所有元素自动缩放适应容器宽度且不换行显示
设置缩减因子: 1 (默认值/初始值)
*/
.demo02 > .item {
flex-shrink: 1;
}
.demo03 > .item:first-of-type {
flex-shrink: 1;
}
.demo03 > .item:nth-of-type(2) {
flex-shrink: 2;
}
.demo03 > .item:last-of-type {
flex-shrink: 3;
}
/*
计算步骤
1 获取基本变量
1.1 多余待缩放空间 ( 250px + 250px + 250px ) - 550px = 200px
1.2 各元素缩减因子:第一个:1,第二个:2,第三个:3
1.3 缩减因子之和:1 + 2 + 3 = 6
2 计算缩减比例
1.1 缩减比例 = 缩减因子 / 缩减因子之和
1.2 第一个元素缩减比例:1 / 6 = 0.167
1.3 第二个元素缩减比例:2 / 6 = 0.333
1.4 第三个元素缩减比例:3 / 6 = 0.5
3 计算每个元素的缩减
3.1 第一个元素:200px * 0.167 = 33.4px
3.2 第二个元素:200px * 0.333 = 66.6px
3.3 第三个元素:200px * 0.5 = 100px
4 计算每个元素的最终宽度
4.1 第一个元素:250px - 33.4px = 216.6px
4.2 第二个元素:250px - 66.6px = 183.4px
4.3 第三个元素:250px - 100px = 150px
*/
.demo04 > .item:first-of-type {
flex-shrink: 0.2;
}
.demo04 > .item:nth-of-type(2) {
flex-shrink: 0.4;
}
.demo04 > .item:last-of-type {
flex-shrink: 0.4;
}
.demo05 > .item:first-of-type {
width: 175px;
flex-shrink: 2;
}
.demo05 > .item:nth-of-type(2) {
width: 225px;
flex-shrink: 2;
}
.demo05 > .item:last-of-type {
width: 410px;
flex-shrink: 5;
}
/*
元素总宽度:175px + 225px + 410px = 810px
容器宽度550px, 于是有260px的等缩减空间, 需要在每个元素中进行摊派
1. 计算缩减因子的缩小比例:等待缩减空间 / 每个弹性元素的宽度与缩减因子乘积的总和
缩减因子的缩小比例:260 / ((175*2)+(225*2)+(410*5)) = 260 / 2850 = 0.091
2. 计算每个元素的缩减量:元素宽度*(缩减因子 * 缩减因子的缩减比例)
第一个元素: 175 * ( 2 * 0.091) = 31.85px
第二个元素: 225 * ( 2 * 0.091) = 40.95px
第三个元素: 410 * ( 5 * 0.091) = 186.55px
3. 计算每个元素最终宽度
第一个元素: 175 - 31.85 = 143.15px
第二个元素: 225 - 40.95 = 184.05px
第三个元素: 410 - 186.55 = 223.45px
*/
</style>
</head>
<body>
<h1>设置弹性元素的缩减因子</h1>
<h3>1. 所有弹性元素不缩减,以原始宽度显示,缩减因子为: 0</h3>
<div class="container flex demo01">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>2. 所有弹性元素自适应容器宽度且不换行,缩减因子: 1 (默认)</h3>
<div class="container flex demo02">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>3. 当三个弹性元素的缩减因子不相等时</h3>
<div class="container flex demo03">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>4. 缩减因子也可以是小数,只要大于0就可以</h3>
<div class="container flex demo04">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>5. 当每个弹性元素宽度不一样时, 完全是另一道风景线</h3>
<div class="container flex demo05">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
</body>
</html>
3. 设置弹性元素的基准尺寸(flex-basis)
定义了在计算分配主轴上剩余空间之前, 项目占据的主轴空间(main size)
CSS语法:flex-basis: number|auto|initial|inherit;
属性值
- number:一个长度单位或者一个百分比,规定灵活项目的初始长度
- auto:默认值。长度等于灵活项目的长度。如果该项目未指定长度,则长度将根据内容决定
- initial:设置该属性为它的默认值
- inherit:从父元素继承该属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>设置弹性元素的基准尺寸</title>
<style>
/*弹性容器通用样式*/
.container {
border: 2px dashed greenyellow;
margin: 15px;
background-color: grey;
width: 550px;
}
/*弹性元素通用样式*/
.item {
box-sizing: border-box;
border: 1px solid red;
padding: 20px;
background-color: lightpink;
}
/*块级弹性容器*/
.flex {
display: flex;
}
/*在未设置弹性元素宽度时, 以内容宽度显示*/
.demo01 > .item {
flex-basis: content;
}
/*存在自定义宽度时,以该宽度显示*/
.demo02 > .item {
width: 100px;
}
/*如果元素设置了宽度,则以该宽度显示*/
/*如果元素的宽度也是auto,或者没有定义, 就按内容宽度content显示*/
.demo03 > .item {
flex-basis: auto;
}
/*当元素存在自定义宽度与基准宽度时, 以基准宽度为准*/
.demo04 > .item {
width: 120px;
flex-basis: 150px;
}
.demo05 > :first-of-type {
flex-basis: 20%;
}
.demo05 > :nth-of-type(2) {
flex-basis: 30%;
}
.demo05 > :last-of-type {
flex-basis: 50%;
}
</style>
</head>
<body>
<h1>flex-basis:设置弹性元素的基准尺寸</h1>
<h3>1: 在未设置弹性元素宽度时, 以内容宽度显示</h3>
<div class="container flex demo01">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>2: 存在自定义宽度时,以该宽度显示</h3>
<div class="container flex demo02">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>3: 自动状态下,由浏览器根据预设值自行判定</h3>
<div class="container flex demo03">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>4: 当元素存在自定义宽度与基准宽度时, 以基准宽度为准</h3>
<div class="container flex demo04">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>5: 元素基准宽度支持百分比设置</h3>
<div class="container flex demo05">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
</body>
</html>
4. 简化弹性元素的基本设置(flex)
flex属性是前面flex-grow,flex-shrink和flex-basis属性的简写
CSS语法:flex: flex-grow flex-shrink flex-basis|auto|initial|inherit;
属性值:
- flex-grow:一个数字,规定项目将相对于其他灵活的项目进行扩展的量
- flex-shrink:一个数字,规定项目将相对于其他灵活的项目进行收缩的量
- flex-basis:项目的长度。合法值:”auto”、”inherit” 或一个后跟 “%”、”px”、”em” 或任何其他长度单位的数字
- auto:与 1 1 auto 相同
- none:与0 0 auto 相同
- initial:设置该属性为它的默认值,即为 0 1 auto
- inherit:从父元素继承该属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>简化弹性元素的基本设置</title>
<style>
/*弹性容器通用样式*/
.container {
border: 2px dashed greenyellow;
margin: 15px;
background-color: grey;
width: 550px;
}
/*弹性元素通用样式*/
.item {
box-sizing: border-box;
border: 1px solid red;
padding: 20px;
background-color: lightpink;
}
/*块级弹性容器*/
.flex {
display: flex;
}
/*根据weight,height计算,并且允许缩减大小适应容器*/
.demo01 > .item {
width: 100px;
height: 60px;
flex: initial;
/*等价于默认值*/
/*flex: 0 1 auto;*/
}
.demo02 > .item {
width: 100px;
height: 60px;
flex: auto;
/*等价于*/
/*flex: 1 1 auto;*/
}
.demo03 > .item {
width: 100px;
height: 60px;
flex: none;
/*等价于: */
/*flex: 0 0 auto;*/
}
.demo04 > .item {
width: 100px;
height: 60px;
flex: 1;
/*等价于*/
/*flex-grow: 1;*/
/*等价于:*/
/*flex: 1 1 auto;*/
}
.demo05 > .item {
width: 100px;
height: 60px;
flex: 1 0 200px;
}
.demo06 > .item {
width: 100px;
height: 60px;
}
.demo06 > .item:first-of-type {
flex: 1 1 20%;
}
/*因为第一个元素设置了可增长,所以20%没用*/
</style>
</head>
<body>
<h1>简化弹性元素的基本设置</h1>
<h3>1: 根据宽度计算,允许缩减适应容器</h3>
<div class="container flex demo01">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>2: 根据宽度计算,元素完全弹性以适应容器</h3>
<div class="container flex demo02">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>3: 元素完全失去弹性, 以原始大小呈现</h3>
<div class="container flex demo03">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>4: 一个数值表示增长因子,其他值默认:flex: 1 1 auto</h3>
<div class="container flex demo04">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>5: 第三个数有具体数值时,以它为计算标准</h3>
<div class="container flex demo05">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
<h3>6: 单独设置某一个元素弹性大小</h3>
<div class="container flex demo06">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
</div>
</body>
</html>
5. 单独设置元素在交叉轴上排列方式(align-self)
该属性允许单个项目有与其它项目不一样的对齐方式, 可覆盖掉容器的flex-items
CSS 语法:align-self: auto|stretch|center|flex-start|flex-end|baseline|initial|inherit;
属性值:
- auto:默认值。元素继承了它的父容器的 align-items 属性。如果没有父容器则为 “stretch”
- stretch:元素被拉伸以适应容器
- center:元素位于容器的中心
- flex-start:元素位于容器的开头
- flex-end:元素位于容器的结尾
- baseline:元素位于容器的基线上
initial:设置该属性为它的默认值 - inherit:从父元素继承该属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>单独设置元素在交叉轴上排列方式</title>
<style>
.container {
border: 2px dashed greenyellow;
margin: 15px;
background-color: grey;
width: 800px;
height: 500px;
/*以主轴垂直为例进行演示*/
flex-flow: column nowrap;
/*默认元素紧贴终止线排列*/
align-items: flex-end;
}
.item {
box-sizing: border-box;
border: 1px solid red;
padding: 20px;
background-color: lightpink;
width: 120px;
height: 60px;
}
.flex {
display: flex;
}
.item:first-of-type {
align-self: auto;
background-color: lightpink;
}
.item:nth-of-type(2) {
width: auto;
align-self: stretch;
background-color: lightseagreen;
}
.item:nth-of-type(3) {
align-self: center;
background-color: lightslategrey;
}
.item:nth-of-type(4) {
align-self: flex-start;
background-color: lightcyan;
}
.item:nth-last-of-type(3) {
align-self: flex-end;
background-color: lightgreen;
}
.item:nth-last-of-type(2) {
align-self: baseline;
background-color: lightblue;
}
.item:last-of-type {
align-self: initial;
background-color: olivedrab;
}
</style>
</head>
<body>
<h1>单独设置元素在交叉轴上排列方式</h1>
<div class="container flex">
<span class="item">auto</span>
<span class="item">stretch</span>
<span class="item">center</span>
<span class="item">flex-start</span>
<span class="item">flex-end</span>
<span class="item">baseline</span>
<span class="item">initial</span>
</div>
</body>
</html>
6. 设置元素的排列顺序(order)
定义项目的排列顺序。数值越小,排列越靠前,默认为0
CSS语法:order: number|initial|inherit;
属性值:
- number:默认值是 0。规定灵活项目的顺序
- initial:设置该属性为它的默认值
- inherit:从父元素继承该属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>设置元素的排列顺序</title>
<style>
.container {
border: 2px dashed red;
background-color: #ededed;
margin: 20px;
display: flex;
width: 600px;
justify-content: center;
}
.item {
width: 100px;
height: 60px;
box-sizing: border-box;
border: 1px solid lightgreen;
padding: 20px;
background-color: yellow;
margin: 0 20px;
}
.item:first-of-type {
order: 1;
}
.item:nth-of-type(2) {
order: 3;
}
.item:nth-last-of-type(2) {
order: 2;
}
.item:last-of-type {
order: 0;
}
</style>
</head>
<body>
<h1>设置元素的排列顺序</h1>
<div class="container">
<span class="item">item1</span>
<span class="item">item2</span>
<span class="item">item3</span>
<span class="item">item4</span>
</div>
</body>
</html>
7. flex实现圣杯布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>flex实现圣杯布局</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
display: flex;
flex-flow: column nowrap;
height: 100vh;
}
header, footer {
height: 60px;
background-color: lightblue;
}
main {
display: flex;
flex: 1;
}
main > article {
flex: 1;
background-color: lightgreen;
}
main > aside {
width: 200px;
background-color: lightseagreen;
}
main > aside:first-of-type {
order: -1;
}
</style>
</head>
<body>
<header>顶部</header>
<main>
<article>主体内容区</article>
<aside>左侧</aside>
<aside>右侧</aside>
</main>
<footer>底部</footer>
</body>
</html>
8. 仿小米商城首页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>仿小米商城首页</title>
<style>
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: white;
}
li {
list-style-type: none;
}
body {
min-width: 1280px;
height: 100vh;
}
header {
height: 40px;
background-color: #333333;
box-sizing: border-box;
}
.container {
box-sizing: border-box;
margin: 0 auto;
width: 1226px;
height: 40px;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
}
.container > a {
color: #B0B0B0;
border-right: 1px solid #424242;
padding-right: 10px;
}
.container > a:nth-last-of-type(5) {
margin-right: 210px;
border-right: none;
}
.container > a:nth-last-of-type(2) {
border-right: none;
margin-right: 10px;
}
.container > a:last-of-type {
padding-right: 0;
border-right: none;
width: 120px;
height: 40px;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
background-color: #424242;
}
.container > a:hover {
color: white;
}
.container > a:last-of-type:hover {
background: white;
color: #FF832F;
cursor: pointer;
}
nav {
margin: 25px auto;
width: 1226px;
height: 55px;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: border-box;
}
nav a {
color: #333333;
font-size: 16px;
}
nav > a:first-of-type > img {
width: 55px;
height: 55px;
}
nav > form {
width: 296px;
height: 50px;
box-sizing: border-box;
display: flex;
}
nav > form > input {
box-sizing: border-box;
flex: 1;
padding: 0 10px;
border: 1px solid #ededed;
border-right: none;
}
nav > form > label {
box-sizing: border-box;
width: 52px;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid #ededed;
}
nav > form > label:hover {
background: #FF6700;
color: white;
cursor: pointer;
}
nav > div {
margin-left: 50px;
}
nav > div > a {
margin: 0 5px;
}
nav > div > a:hover {
color: #FF832F;
}
main {
width: 1226px;
margin: 0 auto;
}
main > article:first-of-type {
display: flex;
box-sizing: border-box;
}
main > article:first-of-type > ul {
background: #8B9DA3;
box-sizing: border-box;
width: 234px;
height: 460px;
display: flex;
flex-flow: column nowrap;
justify-content: center;
}
main > article:first-of-type > ul > li {
box-sizing: border-box;
width: 234px;
height: 42px;
padding: 0 30px;
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
}
main > article:first-of-type > ul > li:hover {
background: #FF6700;
}
main > article:first-of-type > ul > li > span {
color: #ededed;
}
main > article:first-of-type > img {
width: 992px;
height: 460px;
}
main > article:nth-of-type(2) {
display: flex;
box-sizing: border-box;
margin: 20px 0;
justify-content: space-between;
}
main > article:nth-of-type(2) > div {
width: 234px;
height: 170px;
box-sizing: border-box;
background: #5F5750;
padding: 5px;
display: flex;
flex-flow: row wrap;
justify-content: center;
align-items: center;
}
main > article:nth-of-type(2) > div li a {
display: flex;
flex-flow: column nowrap;
align-items: center;
box-sizing: border-box;
margin: 10px;
}
main > article:nth-of-type(2) > div img {
width: 24px;
}
main > article:nth-of-type(2) > div > ul {
display: flex;
}
main > article:nth-of-type(2) > div > ul > li > a > span {
font-size: 12px;
color: #CFCCCA;
margin-top: 3px;
}
main > article:nth-of-type(2) > div > ul > li > a > span:hover {
color: white;
}
main > article:nth-of-type(2) > a {
box-sizing: border-box;
height: 170px;
}
main > article:nth-of-type(2) > a > img {
width: 316px;
height: 170px;
}
main > article:nth-of-type(2) > a:hover {
box-shadow: 0 0 3px #757575;
}
.page-main {
background: #F5F5F5;
height: 600px;
}
.recommend > h2 {
margin-top: 20px;
color: #333333;
font-size: 22px;
font-weight: normal;
}
.recommend {
width: 1226px;
margin: 0 auto;
display: flex;
flex-flow: column nowrap;
}
.recommend > ul {
display: flex;
justify-content: space-between;
box-sizing: border-box;
margin: 20px 0;
}
.recommend > ul > li > a {
box-sizing: border-box;
width: 234px;
height: 340px;
display: flex;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
background: white;
}
.recommend > ul > li:first-of-type > a {
background: #F1EDED;
border-top: 1px solid red;
}
.recommend > ul > li:nth-of-type(2) > a {
border-top: 1px solid #FFAC13;
}
.recommend > ul > li:nth-of-type(3) > a {
border-top: 1px solid #83C44E;
}
.recommend > ul > li:nth-last-of-type(2) > a {
border-top: 1px solid #2196F3;
}
.recommend > ul > li:last-of-type > a {
border-top: 1px solid #E53935;
}
.recommend > ul > li > a > img {
width: 160px;
height: 165.6px;
}
.recommend > ul > li > a > h3 {
margin: 20px 0 5px 0;
color: black;
font-size: 14px;
font-weight: normal;
}
.recommend > ul > li > a > span {
font-size: 12px;
color: #b0b0b0;
margin-bottom: 15px;
}
.recommend > ul > li > a > p > span {
color: #ff6709;
font-size: 14px;
}
.recommend > ul > li > a > p > del {
margin: 5px;
color: #b0b0b0;
font-size: 14px;
}
.recommend > ul > li:first-of-type > a > img {
width: 34px;
height: 53px;
margin: 30px 0;
}
.recommend > ul > li:first-of-type > a > h3 {
font-size: 21px;
color: #ef3a3b;
}
.recommend > ul > li:first-of-type > a > span {
color: rgba(0, 0, 0, .54);
font-size: 15px;
}
.recommend > ul > li:first-of-type > a > p > span {
width: 46px;
height: 46px;
box-sizing: border-box;
background: #605751;
font-size: 24px;
color: #fff;
line-height: 46px;
padding: 6px;
}
.recommend > ul > li:first-of-type > a > p > i {
color: black;
font-size: 20px;
font-style: normal;
margin: 0 5px;
}
.footer1 {
width: 1226px;
height: 80px;
margin: 0 auto;
box-sizing: border-box;
display: flex;
justify-content: space-around;
align-items: center;
border-bottom: 1px solid #E0E0E0;
}
.footer1 > a {
color: #616161;
font-size: 16px;
}
.footer1 > a:hover {
color: #FF6E0B;
}
.footer1 > span {
color: #E0E0E0;
}
.footer2 {
width: 1226px;
height: 192px;
margin: 0 auto;
box-sizing: border-box;
display: flex;
align-items: center;
}
.footer2 > dl {
width: 160px;
height: 112px;
box-sizing: border-box;
}
.footer2 > dl > dt {
font-size: 14px;
margin: 0 0 26px 0;
}
.footer2 > dl > dd {
font-size: 12px;
margin-top: 10px;
}
.footer2 > dl > dd > a {
color: #7F7F7F;
}
.footer2 > dl > dd > a:hover {
color: #FF832F;
}
.footer2 > div {
width: 252px;
height: 112px;
box-sizing: border-box;
border-left: 1px solid #E0E0E0;
margin-left: 15px;
display: flex;
flex-flow: column nowrap;
align-items: center;
}
.footer2 > div > h3 {
font-weight: normal;
font-size: 22px;
color: #FF6700;
margin-bottom: 5px;
}
.footer2 > div > p, span {
font-size: 12px;
color: #616161;
}
.footer2 > div > span {
margin: 2px 0 16px 0;
}
.footer2 > div > button {
width: 120px;
height: 30px;
box-sizing: border-box;
border: 1px solid #FF6700;
font-size: 12px;
color: #FF6700;
background: white;
cursor: pointer;
}
.footer2 > div > button:hover {
background: #FF6700;
color: white;
}
.footer3 {
height: 248px;
background: #FAFAFA;
}
.footer3 > div {
width: 1226px;
height: 200px;
margin: 0 auto;
display: flex;
align-items: center;
}
.footer3 > div > img {
width: 57px;
height: 57px;
align-self: flex-start;
margin-top: 30px;
}
.message {
margin-left: 10px;
}
.message > div:first-of-type > a{
font-size: 12px;
color: #757575;
margin-right: 5px;
}
.message > div:first-of-type > a:hover {
color: #FF832F;
}
.message > p {
font-size: 12px;
color: #B0B0B0;
margin: 2px 0;
}
.message > div:last-of-type > img:first-of-type {
width: 83px;
height: 28px;
}
</style>
</head>
<body>
<header>
<div class="container">
<a href="">小米商城</a>
<a href="">MIUI</a>
<a href="">IoT</a>
<a href="">云服务</a>
<a href="">金融</a>
<a href="">有品</a>
<a href="">小爱开放平台</a>
<a href="">企业团购</a>
<a href="">资历证照</a>
<a href="">协议规则</a>
<a href="">下载app</a>
<a href="">Select Location</a>
<a href="">登录</a>
<a href="">注册</a>
<a href="">消息通知</a>
<a>购物车(0)</a>
</div>
</header>
<nav>
<a href=""><img src="static/images/mi_logo.png" alt=""></a>
<div>
<a href="">小米手机</a>
<a href="">Redmi 红米</a>
<a href="">电视</a>
<a href="">笔记本</a>
<a href="">家电</a>
<a href="">路由器</a>
<a href="">智能硬件</a>
<a href="">服务</a>
<a href="">社区</a>
</div>
<form action="" method="get">
<input type="text" name="search" id="search">
<label for="search">搜索</label>
</form>
</nav>
<main>
<article>
<ul>
<li><a href="">手机 电话卡</a><span>></span></li>
<li><a href="">电视 盒子</a><span>></span></li>
<li><a href="">笔记本 平板</a><span>></span></li>
<li><a href="">家电 插线板</a><span>></span></li>
<li><a href="">出行 穿戴</a><span>></span></li>
<li><a href="">智能 路由器</a><span>></span></li>
<li><a href="">电源 配件</a><span>></span></li>
<li><a href="">健康 儿童</a><span>></span></li>
<li><a href="">耳机 音箱</a><span>></span></li>
<li><a href="">生活 箱包</a><span>></span></li>
</ul>
<img src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/ecac78f468f95f59996ab7978c1de8e3.jpg?thumb=1&w=1533&h=575&f=webp&q=90"
alt="">
</article>
<article>
<div>
<ul>
<li>
<a href="">
<img src="static/images/d1.png" alt="">
<span>小米秒杀</span>
</a>
</li>
<li>
<a href="">
<img src="static/images/d2.png" alt="">
<span>企业团购</span>
</a>
</li>
<li>
<a href="">
<img src="static/images/d3.png" alt="">
<span>F码通道</span>
</a>
</li>
</ul>
<ul>
<li>
<a href="">
<img src="static/images/d4.png" alt="">
<span>米粉卡</span>
</a>
</li>
<li>
<a href="">
<img src="static/images/d5.png" alt="">
<span>以旧换新</span>
</a>
</li>
<li>
<a href="">
<img src="static/images/d6.png" alt="">
<span>话费充值</span>
</a>
</li>
</ul>
</div>
<a href=""><img src="static/images/redmi.jpg" alt=""></a>
<a href=""><img src="static/images/mi9.jpg" alt=""></a>
<a href=""><img src="static/images/huan4.jpg" alt=""></a>
</article>
</main>
<div class="page-main">
<div class="recommend">
<h2>小米闪购</h2>
<ul>
<li>
<a href="">
<h3>00:00 场</h3>
<img src="static/images/light.png" alt="">
<span>距离结束还有</span>
<p><span>07</span><i>:</i><span>35</span><i>:</i><span>46</span></p>
</a>
</li>
<li>
<a href="">
<img src="static/images/m1.jpg" alt="">
<h3>小米AI音箱</h3>
<span>听音乐、语音遥控家电</span>
<p><span>229元</span>
<del>299元</del>
</p>
</a>
</li>
<li>
<a href="">
<img src="static/images/m3.jpg" alt="">
<h3>小米小爱音箱 万能遥控版 黑色</h3>
<span>传统家电秒变智能</span>
<p><span>99元</span>
<del>199元</del>
</p>
</a>
</li>
<li>
<a href="">
<img src="static/images/m2.jpg" alt="">
<h3>Redmi Note 7 6GB+64GB</h3>
<span>4800万拍照千元机</span>
<p><span>1049元</span>
<del>1099元</del>
</p>
</a>
</li>
<li>
<a href="">
<img src="static/images/m4.png" alt="">
<h3>Redmi Note 8 Pro</h3>
<span>6400万全场景四摄</span>
<p><span>1299元</span>
<del>1399元</del>
</p>
</a>
</li>
</ul>
<img src="static/images/m5.png" alt="">
</div>
</div>
<footer>
<div class="footer1">
<a href="">预约维修服务</a>
<span>|</span>
<a href="">7天无理由退货</a>
<span>|</span>
<a href="">15天免费换货</a>
<span>|</span>
<a href="">满150元包邮</a>
<span>|</span>
<a href="">520余家售后网点</a>
</div>
<div class="footer2">
<dl>
<dt>帮助中心</dt>
<dd><a href="">账户管理</a></dd>
<dd><a href="">购物指南</a></dd>
<dd><a href="">订单操作</a></dd>
</dl>
<dl>
<dt>服务支持</dt>
<dd><a href="">售后政策</a></dd>
<dd><a href="">自助服务</a></dd>
<dd><a href="">相关下载</a></dd>
</dl>
<dl>
<dt>线下门店</dt>
<dd><a href="">小米之家</a></dd>
<dd><a href="">服务网点</a></dd>
<dd><a href="">授权体验店</a></dd>
</dl>
<dl>
<dt>关于小米</dt>
<dd><a href="">了解小米</a></dd>
<dd><a href="">加入小米</a></dd>
<dd><a href="">投资者关系</a></dd>
</dl>
<dl>
<dt>关注我们</dt>
<dd><a href="">新浪微博</a></dd>
<dd><a href="">官方微信</a></dd>
<dd><a href="">联系我们</a></dd>
</dl>
<dl>
<dt>特色服务</dt>
<dd><a href="">F码通道</a></dd>
<dd><a href="">礼物码</a></dd>
<dd><a href="">防伪查询</a></dd>
</dl>
<div>
<h3>400-100-5678</h3>
<p>周一至周日 8:00-18:00</p>
<span>(仅收市话费)</span>
<button>人工客服</button>
</div>
</div>
<div class="footer3">
<div>
<img src="static/images/mi_logo.png" alt="">
<div class="message">
<div>
<a href="">小米商城</a><span>|</span>
<a href="">MIUI</a><span>|</span>
<a href="">米家</a><span>|</span>
<a href="">米聊</a><span>|</span>
<a href="">多看</a><span>|</span>
<a href="">游戏</a><span>|</span>
<a href="">路由器</a><span>|</span>
<a href="">米粉卡</a><span>|</span>
<a href="">政企服务</a><span>|</span>
<a href="">小米天猫店</a><span>|</span>
<a href="">小米集团隐私</a><span>|</span>
<a href="">小米公司儿童信息保护规则</a><span>|</span>
<a href="">小米商城隐私政策</a><span>|</span>
<a href="">小米商城用户协议</a><span>|</span>
<a href="">问题反馈</a><span>|</span>
<a href="">廉政举报</a><span>|</span>
<a href="">诚信合规</a><span>|</span>
<a href="">Select Location</a>
</div>
<p>
© mi.com 京ICP证110507号 京ICP备10046444号 京公网安备11010802020134号 京网文[2017]1530-131号<br>
(京)网械平台备字(2018)第00005号 互联网药品信息服务资格证 (京) -非经营性-2014-0090 营业执照 医疗器械公告<br>
增值电信业务许可证 网络食品经营备案(京)【2018】WLSPJYBAHF-12 食品经营许可证<br>
违法和不良信息举报电话:185-0130-1238 知识产权侵权投诉 本网站所列数据,除特殊说明,所有数据均出自我司实验室测试
</p>
<div>
<img src="static/images/fd1.png" alt="">
<img src="static/images/fd2.png" alt="">
<img src="static/images/fd3.png" alt="">
<img src="static/images/fd4.png" alt="">
<img src="static/images/fd5.png" alt="">
</div>
</div>
</div>
</div>
</footer>
</body>
</html>
9. 总结
通过对flex的学习,掌握了flex的全部属性,并通过实例和模仿现成网页加深了对flex的认知和理解。