左右布局:
左边固定,右边自适应
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
}
body{
/* 转换成弹性盒子,自动横向排列 */
display: flex;
}
.left,.right{
width: 200px;
height: 300px;
background-color: red;
}
.center{
height: 400px;
background-color: pink;
/* 自适应宽度 flex:1;*/
flex: 1;
text-align: right;
}
</style>
</head>
<body>
<div class="left">left</div>
<div class="center">center</div>
<!-- <div class="right">right</div> -->
</body>
</html>
圣杯布局:
中心:高度自适应,左右两侧宽度固定死,中间的宽度自适应
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
}
html,body{
/* 高度100%,下一级的属性100%才能生效 */
height: 100%;
}
body{
display: flex;
flex-direction: column;
}
header{
height: 100px;
background-color: red;
}
main{
background-color: pink;
/* 转换成弹性盒子 */
flex: 1;
display: flex;
}
main .left{
width: 100px;
height: 100%;
background-color: aqua;
}
main .right{
width: 100px;
height: 100%;
background-color: rgb(12, 244, 171);
}
main .center{
/* 宽度自适应: flex: 1 ; */
flex: 1;
/* 高度自适应 */
height: 100%;
background-color: blue;
}
footer{
height: 100px;
background-color: green;
}
</style>
</head>
<body>
<header>header</header>
<main>
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</main>
<footer>footer</footer>
</body>
</html>
<!--
圣杯布局:
上:高度固定死
中:高度自适应
左:宽度固定死
中:宽度自适应
右:宽度固定死
下:高度固定死
-->