webveuje/csspress/demo/flex.html

107 lines
2.6 KiB
HTML
Raw Normal View History

2021-01-20 10:33:56 +00:00
<!DOCTYPE html>
<html lang="en">
2021-03-23 02:58:10 +00:00
2021-01-20 10:33:56 +00:00
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
2021-03-23 02:58:10 +00:00
* {
margin: 0;
padding: 0;
2021-01-20 10:33:56 +00:00
}
2021-03-23 02:58:10 +00:00
.box {
2021-01-20 10:33:56 +00:00
width: 1000px;
height: 500px;
background: pink;
2021-03-23 02:58:10 +00:00
display: flex;
/* 通过display:flex来把目标元素设置成flex布局 */
2021-01-20 10:33:56 +00:00
flex-direction: row;
2021-03-23 02:58:10 +00:00
/* flex-direction 属性决定主轴的方向值为row的时候水平排列 起点在左 */
2021-01-20 10:33:56 +00:00
}
2021-03-23 02:58:10 +00:00
.box1 {
2021-01-20 10:33:56 +00:00
width: 1000px;
height: 500px;
background: gold;
2021-03-23 02:58:10 +00:00
display: flex;
flex-direction: row-reverse;
2021-01-20 10:33:56 +00:00
}
2021-03-23 02:58:10 +00:00
.left,
.left1 {
2021-01-20 10:33:56 +00:00
width: 200px;
height: 200px;
background: red;
}
2021-03-23 02:58:10 +00:00
.right,
.right1 {
2021-01-20 10:33:56 +00:00
width: 200px;
height: 200px;
background: blue;
}
2021-03-23 02:58:10 +00:00
.box3 {
flex-direction: column;
}
.box4 {
flex-direction: column-reverse;
}
2021-01-20 10:33:56 +00:00
</style>
</head>
2021-03-23 02:58:10 +00:00
2021-01-20 10:33:56 +00:00
<body>
2021-03-23 02:58:10 +00:00
<div class="box" style="margin-bottom: 15px;">
<div class="left"></div>
<div class="right"></div>
<div>
这里是flex-direction:row的状况 即水平排列 起点在左侧
</div>
</div>
2021-01-20 10:33:56 +00:00
<div class="box">
2021-03-23 02:58:10 +00:00
<div class="left"></div>
<div class="left"></div>
<div class="left"></div>
<div class="left"></div>
<div class="left"></div>
2021-01-20 10:33:56 +00:00
<div class="left"></div>
<div class="right"></div>
2021-03-23 02:58:10 +00:00
<div>
这里是flex-direction:row的状况 即水平排列 起点在左侧
对于溢出的状况flex-wrap 可以定义是否换行
<P>默认属性值为 nowrap 不换行其他属性还有wrap(换行), wrap-reverse(换行,第二行反向排列)</P>
</div>
2021-01-20 10:33:56 +00:00
</div>
<div class="box1">
2021-03-23 02:58:10 +00:00
<div class="right1"></div>
2021-01-20 10:33:56 +00:00
<div class="left1"></div>
2021-03-23 02:58:10 +00:00
<div>
这里是flex-direction:column的状况 即垂直排列 起点在上面
</div>
</div>
<div class="box box3">
<div class="left"></div>
<div class="right"></div>
<div>
这里是flex-direction:column的状况 即垂直排列 起点在下面
</div>
</div>
<div class="box1 box4">
2021-01-20 10:33:56 +00:00
<div class="right1"></div>
2021-03-23 02:58:10 +00:00
<div class="left1"></div>
<div>
这里是flex-direction:column-reverse的状况 即垂直排列 起点在下面
</div>
2021-01-20 10:33:56 +00:00
</div>
</body>
2021-03-23 02:58:10 +00:00
2021-01-20 10:33:56 +00:00
</html>