flex父容器
display:flex // block级
display:inline-flex //inline级
flex-direction:row|column //主轴方向
flex-wrap:nowrap|wrap //换行方式
flex-flow:row wrap ; //含义 flex-direction+flex-wrap
justify-content:flex-start|flex-end|center|space-between|space-around|initial|inherit; // 子元素排列方式
align-items:stretch|center|flex-start|flex-end|baseline|initial|inherit; //交叉方向样式
align-content:center|flex-start|flex-end //多行元素看成一个整体 多行才有效果 单行用align-items
flex子元素
order 排列顺序 从小到大排列
align-self 覆盖父元素align-items 特殊处理
flex-grow 在主轴方向有剩余空间 沿主轴方向填满宽度
flex-shrink 收缩 超出主轴方向 超出部分收缩
flex-basis 初始大小
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flex</title>
<style>
.container {
display: flex;
flex-direction: row;
flex-wrap:nowrap;
justify-content: center;
align-items: center;
align-content: flex-start;
width: 400px;
height: 400px;
margin: 20px 20px 20px 20px;
border: 3px solid black;
}
.item:nth-child(1) {
order: 0;
align-self: flex-start;
width: 100px;
height: 100px;
color: white;
background-color: #000;
}
.item:nth-child(2) {
width: 100px;
height: 100px;
color: white;
background-color: #00f;
}
.item:nth-child(3) {
width: 100px;
height: 100px;
color: white;
background-color: #0ff;
}
.item:nth-child(4) {
width: 100px;
height: 100px;
color: white;
background-color: #eee;
}
.item:nth-child(5) {
height: 100px;
color: white;
width: 100px;
background-color: #f0f;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
</body>
</html>
网友评论