flex-wrap 换行
flex-wrap
主要通过在外层容器中设置它里面的子项目是否可以换行。默认情况下项目是不换行的。
1. 官方定义
flex-wrap 属性规定flex容器是单行或者多行,同时横轴的方向决定了新行堆叠的方向。
2. 解释
3. 语法
flex-wrap: Nowrap|wrap|wrap-reverse|initial|inherit;
属性值
4. 兼容性
IE | Edge | Firefox | Chrome | Safari | Opera | ios | android |
---|---|---|---|---|---|---|---|
10+ | 12+ | 28+ | 4+ | 6.1+ | 12.1+ | 7+ | 4.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>