flex布局
一、flex布局案例
display:flex;
flex-direction: row; //排序的方向,row代表横向排列,column代表纵向排列
justify-content: center; //排列方向的居中
align-items: center; //表示和排列方向对应的垂直方向的居中
flex-wrap: wrap; //换行
二、代码实战
代码的详细解读,可以参考视频教程。
新建 html 文件 12-flex.html
,编写下方程序,运行看看效果吧
<!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 type="text/css">
.out-div{
width: 500px;
height: 600px;
background-color: yellow;
padding: 15px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.in-div{
width:100px;
height: 100px;
background-color: tomato;
margin:15px;
}
</style>
</head>
<body>
<div class="out-div">
<div class="in-div"></div>
<div class="in-div"></div>
<div class="in-div"></div>
</div>
</body>
</html>