左右固定,中自适应布局
利用弹性布局,代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>
.box{
display: flex;
}
.left {
width: 200px;
height: 100px;
float: left;
background-color: red;
}
.right {
width: 120px;
height: 100px;
float: right;
background-color: blue;
}
.middle {
flex: 1;
height: 100px;
background-color: black;
}
</style>
<body>
<div class="box">
<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>
</div>
</body>
</html>
<script>
</script>
左固右适应布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
/* .wrap {
}
.left {
width: 500px;
height: 200px;
background-color: red;
float: left;
}
.right {
margin-left: 500px;
height: 200px;
background-color: blue;
}
*/
/* 方法2 */
.wrap{
height: 200px;
}
.left{
width: 500px;
height: 200px;
float:left;
background:red;
}
.right{
overflow:hidden;
height: 200px;
background:blue;
}
/* 方法3 */
/* .wrap {
display: flex;
}
.left {
width: 200px;
background-color: red;
}
.right {
flex: 1;
height: 200px;
background-color: blue;
} */
</style>
<body>
<div class="wrap">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
上下固定,中适应并出现滚动条
采用定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>
html,body {
height: 100%;
margin:0;
padding:0
}
.header {
height:100px;
line-height:100px;
background:red;
width:100%;
position:absolute;
z-index:5;
top:0;
text-align:center;
}
.footer {
height:100px;
line-height:100px;
background:blue;
width:100%;
position:absolute;
z-index:200;
bottom:0;
text-align:center;
}
.middlebody {
background-color: orange;
width:100%;
overflow:auto;
top:100px;
position:absolute;
z-index:10;
bottom:100px;
}
.middle {
padding: 20px;
}
</style>
<body>
<body>
<div class="header"></div>
<div class="middlebody">
<div class="middle">
<p>dadda</p>
<p>dadda</p>
<p>dadda</p>
<p>dadda</p>
<p>dadda</p>
<p>dadda</p>
</div>
</div>
<div class="footer"></div>
</body>
</body>
</html>
一些布局知识请参考css布局