Flex布局原理
通过给父盒子添加flex属性,来控制子盒子的位置和排列方式。
Flex基础知识
flex-direction属性:决定主轴的方向
flex-wrap属性:决定是否换行
justify-content属性:项目在主轴上的对齐方式
align-items属性:项目在交叉轴上如何对齐
align-content属性:多根轴线的对齐方式
align-self属性:单个项目有与其他项目不一样的对齐方式
实现三点色子
<!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>Flex布局实现三点色子</title>
<style>
div{
/* 使用Flex布局 */
display: flex;
/* 两端对齐 */
justify-content: space-between;
/* 垂直排列 */
flex-direction:column;
width: 150px;
height: 150px;
border-radius: 10px;
background-color: #ccc;
}
.item{
width: 30px;
height: 30px;
border-radius: 50%;
background-color: #000;
}
.item:nth-child(2){
/* 第二项居中对齐 */
align-self: center;
}
.item:nth-child(3){
/* 第三项结尾对齐 */
align-self: flex-end;
}
</style>
</head>
<body>
<div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</body>
</html>