flex-wrap作用:子元素在父元素盒子中是否换行(列)
属性值 | 作用 |
---|---|
nowrap | 默认值,不换行或不换列 |
wrap | 换行或换列 |
wrap-reverse | 换行或换行,但以相反的顺序 |
示例:
父元素宽度不够,设置子元素自动换行。
<!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>Document</title>
<style>
#div0{
width:300px;
background-color: violet;
/* 父元素flex布局 */
display:flex;
flex-wrap: wrap;
}
#div0 div{
width: 100px;
height: 100px;
background-color: yellow;
}
</style>
</head>
<body>
<div id="div0">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</body>
</html>