flex是css3中引入的一種佈局方式,可以非常靈活高效控制元素的排列與對齊方式,大多數人稱之為彈性佈局.
#flex-direction
| 主軸方向 |
flex-wrap
| #換行樣式 |
flex-flow
| 前兩者的簡寫形式 |
justify-content
| #主軸對齊方式 |
align-items
| 單行的副軸對齊方式 |
align-content
| 多行的副軸對齊方式 |
五、flex-direction,设置主轴的对齐方向,有四个值:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>flex布局 - by ghostwu</title>
<style>
#box {
display: flex;
flex-direction: row;
}
#box p {
width: 100px;
height: 100px;
background: #09f;
margin: 10px;
}
</style>
</head>
<body>
<p id="box">
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
<p>10</p>
<p>11</p>
<p>12</p>
<p>13</p>
<p>14</p>
</p>
</body>
</html>
flex-direction设置为row:
flex-direction设置为row-reverse
flex-direction设置为column,下面的示意图我只截取了前面5个p,后面如果截取的话,图片占的位置太多了,影响体验.
flex-direction设置为column-reverse:
六、flex-wrap :定义子元素超过一行,如何换行,常用属性值:
1 #box {
2 display: flex;
3 flex-direction: row;
4 flex-wrap: nowrap;
5 }
flex-wrap:nowrap;
flex-wrap: wrap;
flex-wrap: wrap-reverse;
七、flex-flow:是flex-direction 和flex-wrap的简写形式,默认是 row nowrap
#box {
display:flex;
/* flex-flow: row nowrap; */
/* flex-flow: row wrap; */
/* flex-flow: row wrap-reverse; */
/* flex-flow: row-reverse wrap-reverse; */
flex-flow: column wrap;
}
八、 justify-content: 子元素在主轴对齐方式
#box {
display:flex;
flex-flow: row wrap;
/* justify-content: flex-start; */
/* justify-content: flex-end; */
/* justify-content: center; */
/* justify-content: space-between; */
justify-content: space-around;
}
这里主要搞清楚space-between和space-around的区别
justify-content: space-between;
justify-content: space-around;