flex-wrap 换行flex-wrap 主要通过在外层容器中设置它里面的子项目是否可以换行。默认情况下项目是不换行的。 1. 官方定义flex-wrap 属性规定flex容器是单行或者多行,同时横轴的方向决定了新行堆叠的方向。 2. 解释默认情况下,设置了 display:flex 的容器是不会换行的,这时候如果我们希望它换行就可以通过 flex-wrap设置超出宽度换行,也可以设置它如何换行,既换行之后的排列的方向。 3. 语法flex-wrap: Nowrap|wrap|wrap-reverse|initial|inherit; 属性值
4. 兼容性
5. 实例
.demo{
display: flex;
flex-wrap: wrap;
}
.item{
width: px;
height: px;
line-height: px;
background: #ccc;
border-right: px solid #fff;
text-align: center;
}效果图
<!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>
.demo{
display: flex;
flex-wrap: wrap;
}
.item{
width: px;
height: px;
line-height: px;
background: #ccc;
border-right: px solid #fff;
text-align: center;
}
</style>
</head>
<body>
<div class="demo">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
</body>
</html>
.demo{
display: flex;
flex-wrap: wrap-reverse;
}
.item{
width: px;
height: px;
line-height: px;
background: #ccc;
border-right: px solid #fff;
text-align: center;
}效果图
<!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>
.demo{
display: flex;
flex-wrap: wrap-reverse;
}
.item{
width: px;
height: px;
line-height: px;
background: #ccc;
border-right: px solid #fff;
text-align: center;
}
</style>
</head>
<body>
<div class="demo">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
</body>
</html>6. 小结flex 弹性盒模型默认是不换行的既 Nowrap |