webveuje/csspress/demo/flexjiaochazhou.html
2021-03-23 10:58:10 +08:00

112 lines
3.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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的时候水平排列 起点在左 */
align-items: center;
}
.box1{
width: 1000px;
height: 500px;
background: gold;
display:flex;
flex-direction: row;
align-items: flex-start;
}
.left,.left1{
width: 200px;
height: 200px;
background: red;
}
.right,.right1{
width: 200px;
height: 200px;
background: blue;
}
.box3{
align-items: flex-end;
}
.box4{
align-items: baseline ;
}
.box5{
align-items: stretch;
}
.lefta{
height:auto
}
.boxfin{
flex-direction: column;
align-items: center;
}
</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;">
上面是 align-items:center 居中的状况
</div>
<div class="box1">
<div class="left"></div>
<div class="right"></div>
</div>
<div style=" margin-bottom: 30px;">
上面是 align-items: flex-start; 起点在上面
</div>
<div class="box box4">
<div class="left"></div>
<div class="right"></div>
</div>
<div style=" margin-bottom: 30px;">
上面是 align-items:base-line 项目的第一行文字的基线对齐的情况
</div>
<div class="box1 box5">
<div class="left lefta"></div>
<div class="right lefta"></div>
</div>
<div style=" margin-bottom: 30px;">
上面是 align-items:stretch默认值 如果项目未设置高度或设为auto将占满整个容器的高度。
</div>
<div class="box1 boxfin">
<div class="left"></div>
<div class="right"></div>
</div>
<div class="zong">
总结1flex-direction属性定义的是主轴方向默认为水平所以 交叉轴方向默认为垂直;
<p>当 flex-direction的值为column的时候align-items决定的就是垂直方向的排列方式</p>
<b>align-items决定的是交叉轴的排列方式 而不一定是单指 垂直的排列方式</b>
</div>
</body>
</html>