flex-direction: column;
justify-content: space-around;
align-items: center;
父级:
display: flex; 如果用了弹性布局,子元素不需要浮动float
父级身上的其他属性:
flex-direction: column;子元素排列方式(纵向排列或横向排列)
column纵向排列
column-reverse纵向翻转排列
row横向排列
row-reverse横向反转排列
justify-content: center;子元素水平排列方式
center居中
pace-between两端对齐
space-around拉手平分
flex-start居左
flex-end居右
align-items: center;子元素垂直排列
center居中
flex-start顶部
flex-end底部
flex-wrap: nowrap;子元素是否在一行显示
nowrap不换行
wrap换行
align-content: center;子元素多行的时候,垂直排列
center居中
flex-start顶部
flex-end底部
flex-flow: <flex-direction> <flex-wrap>;
子元素:
flex: 1000;(系数) 子元素在划分父元素宽度时,先刨除固定宽度
flex-grow: 1;定义子元素放大比例
align-self: flex-start;
其实就是用来覆盖父级align-items垂直排列(父级必须使用align-items属性否则align-self无效)
order: 1;规定子元素顺序,排序,
数值越小,越靠前,默认值为0
<!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;
list-style: none;
}
/* 父级:
display: flex;
如果用了弹性布局,子元素不需要浮动float
父级身上的其他属性:
flex-direction: column;子元素排列方式(纵向排列或横向排列)
column纵向排列
column-reverse纵向翻转排列
row横向排列
row-reverse横向反转排列
justify-content: center;子元素水平排列方式
center居中
pace-between两端对齐
space-around拉手平分
flex-start居左
flex-end居右
align-items: center;子元素垂直排列
center居中
flex-start顶部
flex-end底部
*/
.box {
width: 500px;
height: 500px;
border: 1px solid #000000;
margin: 20px;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
}
.div {
width: 100px;
height: 100px;
background-color: red;
font-size: 40px;
color: #ffffff;
text-align: center;
line-height: 100px;
}
</style>
</head>
<body>
<div class="box">
<div class="div">1</div>
<div class="div">2</div>
</div>
</body>
</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;
list-style: none;
}
/* 父级:
display: flex;
如果用了弹性布局,子元素不需要浮动float
父级身上的其他属性:
flex-direction: column;子元素排列方式(纵向排列或横向排列)
column纵向排列
column-reverse纵向翻转排列
row横向排列
row-reverse横向反转排列
justify-content: center;子元素水平排列方式
center居中
pace-between两端对齐
space-around拉手平分
flex-start居左
flex-end居右
align-items: center;子元素垂直排列
center居中
flex-start顶部
flex-end底部
flex-wrap: nowrap;子元素是否在一行显示
nowrap不换行
wrap换行
align-content: center;子元素多行的时候,垂直排列
center居中
flex-start顶部
flex-end底部
flex-flow: <flex-direction> <flex-wrap>;
*/
.box {
width: 500px;
height: 500px;
border: 1px solid #000000;
margin: 20px;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: row;
flex-wrap: wrap;
align-content: center;
}
.div {
width: 100px;
height: 100px;
background-color: red;
font-size: 40px;
color: #ffffff;
text-align: center;
line-height: 100px;
}
</style>
</head>
<body>
<div class="box">
<div class="div">1</div>
<div class="div">2</div>
<div class="div">3</div>
<div class="div">4</div>
<div class="div">5</div>
<div class="div">6</div>
<div class="div">7</div>
</div>
</body>
</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;
list-style: none;
}
/*
子元素:
flex: 1000(系数)
子元素在划分父元素宽度时,先刨除固定宽度
flex-grow: 1;定义子元素放大比例
align-self: flex-start;
其实就是用来覆盖父级align-items垂直排列(父级必须使用align-items属性否则align-self无效)
order: 1;规定子元素顺序,排序,
数值越小,越靠前,默认值为0
*/
.box {
width: 500px;
height: 500px;
border: 1px solid #000000;
margin: 20px;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
align-items: center;
}
.div {
width: 100px;
height: 100px;
background-color: red;
font-size: 40px;
color: #ffffff;
text-align: center;
line-height: 100px;
border: 1px solid black;
box-sizing: border-box;
flex-grow: 1;
order: 1;
}
.item1 {
align-self: flex-start;
order: 0;
}
</style>
</head>
<body>
<div class="box">
<div class="div">1</div>
<div class="div">2</div>
<div class="div">3</div>
<div class="div">4</div>
<div class="div">5</div>
<div class="div">6</div>
<div class="div">7</div>
<div class="div item1">8</div>
</div>
</body>
</html>