justify-content: 決定flex items 在主軸上的對齊方式
-
flex-start
-
flex-end
-
center
-
space-between
-
space-evenly
-
space-around
代碼
<!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>
#box{
/* 開啓flex佈局:塊元素 */
display: flex;
/* 開啓flex佈局;行元素 */
/* display: inline-flex; */
background-color: red;
width: 600px;
/* 水平居中 */
margin: 0 auto;
/* flex-start: 默認值 main start對齊
flex-end: main end 對齊
center: 主軸中間對齊
space-between: 左右對齊等分主軸
space-around: 左右等分間隙然後等分
space-evenly: 左右窄,中間等分
*/
justify-content: space-around;
}
.item{
text-align: center;
line-height: 100px;
width: 100px;
}
.item1{
background-color: azure;
}
.item2{
background-color: green;
}
.item3{
background-color: gold;
}
</style>
</head>
<body>
<div id="box">
<div class="item item1">item1</div>
<div class="item item2">item2</div>
<div class="item item3">item3</div>
</div>
<strong>行類元素</strong>
</body>
</html>