一、伸缩布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>伸缩布局</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
section {
height: 300px;
width: 80%;
margin: 100px auto;
display: flex;
}
section div {
height: 100%;
flex: 1;
}
section div:nth-child(1) {
background-color: pink;
flex: 2;
}
section div:nth-child(2) {
background-color: blue;
}
section div:nth-child(3) {
background-color: yellow;
flex: 3;
}
</style>
</head>
<body>
<section>
<div></div>
<div></div>
<div></div>
</section>
</body>
</html>
二、伸缩布局之固定宽度
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>伸缩布局固定宽度</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
section {
width: 100%;
height: 300px;
display: flex;
}
section:div {
flex: 1;
}
section div:nth-child(1){
width: 200px;
background-color: pink;
}
section div:nth-child(2){
flex: 2;
background-color: purple;
margin: 0 10px;
}
section div:nth-child(3){
flex: 3;
background-color: blue;
}
</style>
</head>
<body>
<section>
<div>1</div>
<div>2</div>
<div>3</div>
</section>
</body>
</html>
三、伸缩布局之水平分布
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>伸缩布局水平分布</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
section {
width: 80%;
height: 300px;
margin: 100px auto;
display: flex;
min-width: 200px;
flex-direction: column;
}
section:div {
flex: 1;
}
section div:nth-child(1){
background-color: pink;
}
section div:nth-child(2){
background-color: purple;
}
section div:nth-child(3){
background-color: blue;
}
</style>
</head>
<body>
<section>
<div>1</div>
<div>2</div>
<div>3</div>
</section>
</body>
</html>