先上结果图
页面缩小时
第一种方法代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.main{
width: 100%;
background: red;
overflow: hidden;
position: relative;
}
.left{
width: 200px;
height: 500px;
background: yellow;
float: left;
}
.right{
width: 200px;
height: 500px;
background: green;
float: right;
}
.middle{
background: rosybrown;
position: absolute;
top: 0;
left: 210px;
height: 500px;
width: calc(100% - 420px);
}
</style>
</head>
<body>
<div class="main">
<div class="middle">middle</div>
<div class="left">left</div>
<div class="right">right</div>
</div>
</body>
</html>
第二种方法:
<style>
html,body{
margin: 0;
height: 100%;
}
.body{
width: 100%;
height: 100%;
float: left;
}
.main{
margin: 0 210px;
height: 100%;
background: red;
}
.left,.right{
float: left;
width: 200px;
height: 100%;
}
.left{
margin-left: -100%;
background: green;
}
.right{
margin-left: -200px;
background: blue;
}
</style>
<body>
<div class="body">
<div class="main"></div>
</div>
<div class="left"></div>
<div class="right"></div>
</body>