用圣杯布局实现两边宽度固定,中间自适应。
代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
*{
margin:0;
padding:0;
}
header,footer{
width: 100%;
height: 40px;
background-color: aquamarine;
}
.main{
height: 100px;
overflow: hidden;
padding: 0 200px;
}
.middle{
width: 100%;
height: 100px;
background-color: antiquewhite;
float: left;
}
.left{
margin-left: -100%;
width: 200px;
height: 100px;
background-color: greenyellow;
float: left;
position: relative;
left: -200px;
}
.right{
margin-left: -200px;
width: 200px;
height: 100px;
float: left;
background-color: lightblue;
position: relative;
right: -200px;
}
</style>
</head>
<body>
<header>header</header>
<div class="main">
<div class="middle">middle</div>
<div class="left">left</div>
<div class="right">right</div>
</div>
<footer>footer</footer>
</body>
</html>
效果图

网友评论