1.- flex 子项目占的份数
- align-self 控制子项自己在侧轴的排列方式
- order属性定义子项的排列顺序(前后是顺序)
2.flex属性
flex属性定义子项目分配剩余空间,用flex来表示占多少份数。
.item{
flex:<number>;/*default 0*/
}
flex: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>
section {
display:flex;
width:60%;
height:150px;
background-color: pink;
margin:0 auto;
}
section div:nth-child(1){
width: 100px;
height: 150px;
background-color: aqua;
}
section div:nth-child(2){
flex:1;
width: 100px;
height: 150px;
background-color: rgba(129, 248, 113, 0.424);
}
section div:nth-child(3){
width: 100px;
height: 150px;
background-color: rgb(248, 31, 165);
}
</style>
</head>
<body>
<section>
<div></div>
<div></div>
<div></div>
</section>
</body>
</html>
平均分成三等分
三个span标签没有设置宽度,从布局角度来说剩余宽度就是整个宽度,从整个宽度里面再分成三份,各占三分之一
<!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>
section {
display:flex;
width:60%;
height:150px;
background-color: pink;
margin:0 auto;
}
section div:nth-child(1){
width: 100px;
height: 150px;
background-color: aqua;
}
section div:nth-child(2){
flex:1;
width: 100px;
height: 150px;
background-color: rgba(129, 248, 113, 0.424);
}
section div:nth-child(3){
width: 100px;
height: 150px;
background-color: rgb(248, 31, 165);
}
p{
display:flex;
width:60%;
height:150px;
background-color: rgb(251, 129, 72);
margin:100px auto;
}
p span{
flex:1;
}
</style>
</head>
<body>
<section>
<div>1</div>
<div>2</div>
<div>3</div>
</section>
<p>
<span>1</span>
<span>2</span>
<span>3</span>
</p>
</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>
section {
display:flex;
width:60%;
height:150px;
background-color: pink;
margin:0 auto;
}
section div:nth-child(1){
width: 100px;
height: 150px;
background-color: aqua;
}
section div:nth-child(2){
flex:1;
width: 100px;
height: 150px;
background-color: rgba(129, 248, 113, 0.424);
}
section div:nth-child(3){
width: 100px;
height: 150px;
background-color: rgb(248, 31, 165);
}
p{
display:flex;
width:60%;
height:150px;
background-color: rgb(251, 129, 72);
margin:100px auto;
}
p span{
flex:1;
}
p span:nth-child(2) {
flex:2;
background-color: green;
}
</style>
</head>
<body>
<section>
<div>1</div>
<div>2</div>
<div>3</div>
</section>
<p>
<span>1</span>
<span>2</span>
<span>3</span>
</p>
</body>
</html>
flex就是从剩余空间中分配份数,flex值越大分配的份额越多