父元素常见属性

image.png
flex-direction 设置主轴方向

image.png

image.png
justify-content 主轴上子元素排列方式

image.png
flex-wrap 设置子元素是否换行

image.png
align-items设置侧轴上的子元素排列(单行)

image.png
align-items设置侧轴上的子元素排列(多行)

image.png

image.png
flex-flow 复合属性

image.png
子元素常见属性

image.png
flex 定义子项目占据的剩余空间

image.png
align-self 控制子项自己在侧轴上的排列方式

image.png
order 定义项目的排列顺序

image.png
index.html
<!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>flex布局</title>
</head>
<style>
#test1 {
width: 500px;
height: 300px;
background-color: rgb(12, 211, 45);
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
/* align-items: center; */
align-content: space-between;
margin-bottom: 10px;
}
#test1 span {
width: 150px;
height: 100px;
background-color: pink;
}
section {
display: flex;
width: 60%;
height: 150px;
background-color: pink;
margin: 0 auto;
}
section div:nth-child(1) {
width: 100px;
height: 150px;
background-color: blue;
}
section div:nth-child(2) {
flex: 1;
background-color: red;
}
section div:nth-child(3) {
width: 100px;
height: 150px;
background-color: blue;
}
p {
display: flex;
width: 60%;
height: 150px;
background-color: pink;
margin: 10px auto;
}
p span {
flex: 1;
}
p span:nth-child(2) {
flex: 2;
background-color: brown;
}
</style>
<body>
<div id="test1">
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
</div>
<section id="test2">
<div>1</div>
<div>2</div>
<div>3</div>
</section>
<p><span>1</span><span>2</span><span>3</span></p>
</body>
</html>

image.png
网友评论