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

107 lines
2.6 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 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的时候水平排列 起点在左 */
}
.box1 {
width: 1000px;
height: 500px;
background: gold;
display: flex;
flex-direction: row-reverse;
}
.left,
.left1 {
width: 200px;
height: 200px;
background: red;
}
.right,
.right1 {
width: 200px;
height: 200px;
background: blue;
}
.box3 {
flex-direction: column;
}
.box4 {
flex-direction: column-reverse;
}
</style>
</head>
<body>
<div class="box" style="margin-bottom: 15px;">
<div class="left"></div>
<div class="right"></div>
<div>
这里是flex-direction:row的状况 即水平排列 起点在左侧
</div>
</div>
<div class="box">
<div class="left"></div>
<div class="left"></div>
<div class="left"></div>
<div class="left"></div>
<div class="left"></div>
<div class="left"></div>
<div class="right"></div>
<div>
这里是flex-direction:row的状况 即水平排列 起点在左侧
对于溢出的状况flex-wrap 可以定义是否换行
<P>默认属性值为 nowrap 不换行其他属性还有wrap(换行), wrap-reverse(换行,第二行反向排列)</P>
</div>
</div>
<div class="box1">
<div class="right1"></div>
<div class="left1"></div>
<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">
<div class="right1"></div>
<div class="left1"></div>
<div>
这里是flex-direction:column-reverse的状况 即垂直排列 起点在下面
</div>
</div>
</body>
</html>