默认情况下,项目都排在一条线(又称“轴线”)上。flex-wrap 属性定义,flex 布局中默认是不换行的。
如果装不开,会缩小子元素的宽度,放到父元素里面
属性值 | 说明 | |
---|---|---|
nowrap | 默认值,不换行 | |
wrap | 换行 |
<!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>
div {
display: flex;
width: 500px;
height: 500px;
background-color: blue;
flex-direction: row;
flex-wrap: wrap;
}
div span {
width: 100px;
height: 100px;
margin: 10px;
background-color: red;
}
</style>
</head>
<body>
<div>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
</div>
</body>
</html>