Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:
flex容器 | 描述 | 属性 |
---|---|---|
flex-flow |
主轴方向与换行 | row/column norap/wrap |
justify-content |
项目在主轴上的对齐方式 | 默认:flex-start 项目位于容器结尾:flex-end 项目位于容器的中心:center 两端对齐:space-between 分散对齐:space-around 平均对齐:space-evenly |
align-items |
项目在交叉轴上的对齐方式 | 默认拉伸:stretch 元素位于容器中心:center 元素位于容器开头:flex-start 元素位于容器结尾:flex-end |
align-content |
项目在多行容器中的交叉轴上的对齐方式 | 默认拉伸:stretch 元素位于容器的中心:center 元素位于容器的开头:flex-start 元素位于容器结尾:flex-end 两端对齐:space-between 分散对齐:space-around 平均对齐:space-evenly |
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>主轴方向与换行</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
background-color: skyblue;
height: 15em;
display: flex;
margin: 1em;
padding: 2em;
border: 2px solid red;
}
.container>.item {
border: 1px solid black;
background-color: lightcyan;
height: 5em;
width: 5em;
}
.container {
/* 水平方向是row 垂直方向是column 换行wrap 不换行nowrap */
/* 水平方向 不换行 */
flex-flow: row nowrap;
/* 水平方向 换行显示 */
flex-flow: row wrap;
/* 垂直方向 不换行 */
flex-flow: column nowrap;
/* 垂直方向 换行 */
flex-flow: column wrap;
}
</style>
</head>
<body>
<div class="container">
<div class="item">test1</div>
<div class="item">test2</div>
<div class="item">test3</div>
<div class="item">test4</div>
<div class="item">test5</div>
<div class="item">test6</div>
</div>
</body>
</html>
演示截图
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>项目在主轴上的对齐方式</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
background-color: lightcyan;
border: 1px solid black;
height: 15em;
margin: 1em;
padding: 1em;
display: flex;
}
.container>.item {
background-color: lightblue;
border: 1px solid black;
height: 5em;
width: 5em;
}
.container {
/* 1.将所有项目视为一个整体,在项目组两边进行分配 */
/* 右对齐 */
justify-content: flex-start;
/* 左对齐 */
justify-content: flex-end;
/* 居中显示 */
justify-content: center;
/* 2.将项目视为一个个独立的个体,在项目之间进行分配 */
/* 两端对齐 */
justify-content: space-between;
/* 分散对齐 */
justify-content: space-around;
/* 平均对齐 */
justify-content: space-evenly;
}
</style>
</head>
<body>
<div class="container">
<div class="item">test1</div>
<div class="item">test2</div>
<div class="item">test3</div>
<div class="item">test4</div>
<div class="item">test5</div>
<div class="item">test6</div>
</div>
</body>
</html>
演示截图
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>项目在交叉轴上的对齐方式</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
background-color: skyblue;
border: 3px solid red;
padding: 1em;
margin: 1em;
display: flex;
height: 15em;
}
.container>.item {
background-color: yellow;
border: 1px solid red;
height: 5em;
width: 5em;
}
.container {
/* 默认,拉伸子元素 */
align-items: stretch;
/* 位于元素容器顶部 */
align-items: flex-start;
/* 位于元素容器底部 */
align-items: flex-end;
/* 元素位于容器中心 */
align-items: center;
}
</style>
</head>
<body>
<div class="container">
<div class="item">test1</div>
<div class="item">test2</div>
<div class="item">test3</div>
<div class="item">test4</div>
<div class="item">test5</div>
<div class="item">test6</div>
</div>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>项目在多行容器中的交叉轴上的对齐方式</title>.
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
background-color: lightgreen;
border: 1px solid red;
height: 25em;
margin: 1em;
padding: 1em;
display: flex;
}
.container>.item {
background-color: skyblue;
border: 1px solid red;
height: 5em;
width: 8em;
}
.container {
flex-flow: row wrap;
/* 拉伸对齐 */
align-content: stretch;
/* 位于容器的中心 */
align-content: center;
/* 位于容器的开头 */
align-content: flex-start;
/* 位于容器结尾 */
align-content: flex-end;
/* 两端对齐 */
align-content: space-between;
/* 分散对齐 */
align-content: space-around;
/* 平均对齐 */
align-content: space-evenly;
}
</style>
</head>
<body>
<div class="container">
<div class="item">test1</div>
<div class="item">test2</div>
<div class="item">test3</div>
<div class="item">test4</div>
<div class="item">test5</div>
<div class="item">test6</div>
<div class="item">test7</div>
<div class="item">test8</div>
<div class="item">test9</div>
<div class="item">test10</div>
<div class="item">test11</div>
<div class="item">test12</div>
</div>
</body>
</html>
演示截图
flex项目 | 描述 | 属性 |
---|---|---|
flex | 项目的伸缩与宽度 | 放大(0禁止 1开启) 收缩(0禁止 1开启) 基准宽度(使用auto) |
align-self | 项目的对齐方式 | 默认:stretch 位于项目顶部:flex-start 位于项目底部:flex-end 位于项目中心:center |
order | 项目在主轴上的排列顺序 | 0默认,支持负值 |
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>项目的伸缩与宽度</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
background-color: skyblue;
border: 2px solid red;
height: 15em;
margin: 1em;
padding: 1em;
display: flex;
}
.container>.item {
background-color: lightcyan;
border: 1px solid black;
height: 2em;
width: 5em;
}
.container>.item {
/* flex: flex-gro flex-shrink flex-basis */
/* flex: 放大因子 收缩因子 项目在主轴上的基准宽度 */
/* 默认值:不放大或收缩 */
flex: 0 1 auto;
/* 放大 收缩 */
flex: 1 1 auto;
/* 禁止放大 收缩 */
flex: 0 0 auto;
/* 如果只有一个数字,省略掉后面两个参数,表示的放大因子 */
flex: 1;
/* flex通常不会用来设置所有项目的默认选项,通常用来设置某一个项目的特征,也就是定制 */
}
</style>
</head>
<body>
<div class="container">
<div class="item">test1</div>
<div class="item">test2</div>
<div class="item">test3</div>
<div class="item">test4</div>
<div class="item">test5</div>
<div class="item">test6</div>
</div>
</body>
</html>
演示截图
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>设置某个项目的对齐方式</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
background-color: lightblue;
border: 3px solid black;
margin: 2em;
padding: 2em;
height: 15em;
display: flex;
}
.container>.item {
background-color: lightgreen;
border: 1px solid red;
width: 5em;
}
.container>.item:nth-of-type(3) {
align-self: stretch;
/* 上对齐 */
align-self: flex-start;
/* 下对齐 */
align-self: flex-end;
/* 居中 */
align-self: center;
}
</style>
</head>
<body>
<div class="container">
<div class="item">test1</div>
<div class="item">test2</div>
<div class="item">test3</div>
<div class="item">test4</div>
</div>
</body>
</html>
演示截图
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>主轴排列顺序</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
background-color: violet;
border: 2px solid yellow;
margin: 1em;
padding: 1em;
display: flex;
height: 15em;
}
.container>.item {
background-color: lightblue;
border: 1px solid lightseagreen;
width: 8em;
}
.container>.item:first-of-type {
order: 1;
background-color: yellow;
}
.container>.item:nth-of-type(2) {
order: -1;
background-color: lightgreen;
}
.container>.item:nth-of-type(2)+* {
order: 0;
background-color: red;
}
.container>.item:last-of-type {
order: 4;
}
</style>
</head>
<body>
<div class="container">
<div class="item">test1</div>
<div class="item">test2</div>
<div class="item">test3</div>
<div class="item">test4</div>
</div>
</body>
</html>
演示截图