webveuje/csspress/demo/flex1pailie.html

86 lines
2.3 KiB
HTML
Raw Normal View History

2021-03-23 10:58:10 +08:00
<!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>
*{
margin:0;
padding:0;
}
.box{
width: 1000px;
height: 500px;
background: pink;
display:flex;
/* 通过display:flex来把目标元素设置成flex布局 */
flex-direction: row;
/* flex-direction 属性决定主轴的方向值为row的时候水平排列 起点在左 */
justify-content: center;
}
.box1{
width: 1000px;
height: 500px;
background: gold;
display:flex;
flex-direction: row;
justify-content: space-between;
}
.left,.left1{
width: 200px;
height: 200px;
background: red;
}
.right,.right1{
width: 200px;
height: 200px;
background: blue;
}
.box3{
justify-content: space-around;
}
.box4{
flex-direction: column-reverse;
}
</style>
</head>
<body>
<div style="margin-bottom: 50px;">
注:以下所有实例 基于flex-direction:row的情况即水平排列 起点在左边
</div>
<div class="box">
<div class="left"></div>
<div class="right"></div>
</div>
<div style=" margin-bottom: 30px;">
上面是 justify-content:center 居中的状况
</div>
<div class="box1">
<div class="left"></div>
<div class="right"></div>
</div>
<div style=" margin-bottom: 30px;">
上面是 justify-content:space-between 居中的状况
两端对齐 项目之间的间隔都相等
</div>
<div class="box box3">
<div class="left"></div>
<div class="right"></div>
</div>
<div style=" margin-bottom: 30px;">
上面是 justify-content:space-around 居中的状况
每个项目两侧的间隔相等 项目到边框有间距
即两端不对齐
</div>
</body>
</html>