圣杯布局

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
}
body{
min-width: 550px;
}
.container{
background-color: red;
padding-left: 200px;
padding-right: 150px;
}
.center {
width: 100%;
background-color: green;
float: left;
height: 500px;
}
.left{
width: 200px;
height: 100px;
float: left;
background-color: pink;
margin-left: -100%;
position: relative;
top: 0;
right: 200px;
}
.right{
width: 150px;
background-color: purple;
height: 100px;
float: left;
margin-right: -100%;
}
</style>
</head>
<body>
<div class="container">
<div class="center"></div>
<div class="left"></div>

<div class="right"></div>
</div>
</body>
</html>
主要思想是container中设置pl,pr;包裹left,center,right。全部左浮。其中center宽度设置100%,那么left,和right被挤下去了。left通过利用margin-left:-100%,然后再定位,右移。right通过设置margin-right设置-100%,使其在右边。
记得要给body设置最小宽度。最小宽度为:left和right的宽度加上left右移的距离。
posted @ 2019-08-18 15:32  菜鸟小何  阅读(203)  评论(0编辑  收藏  举报