<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.container{
position: relative;
}
.left{
width: 200px;
height: 100px;
background-color: blue;
position: absolute;
top: 0;
left: 0;
}
.right{
width: 200px;
height: 100px;
background-color: green;
position: absolute;
top: 0;
right: 0;
}
.center{
height: 100px;
background-color: red;
margin: 0 200px;
}
</style>
</head>
<body>
<div class="container">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
</body>
</html>
左右绝对定位,中间使用margin空出左右元素所占据的空间。
该方法有个明显的缺点,就是如果中间栏含有最小宽度限制,或是含有宽度的内部元素,当浏览器宽度小到一定程度,会发生层重叠的情况。