三列布局(定位)
1.兩邊固定,中間自適應
2.當中列要完整顯示
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
body{
/*2*left+right*/
min-width: 600px;
}
div{
height: 100px;
}
#left,#right{
width: 200px;
background: pink;
}
#left{
position: absolute;
left: 0;
top: 0;
}
#right{
position: absolute;
right: 0;
top: 0;
}
#middle{
background: yellow;
padding: 0 200px;
}
</style>
</head>
<!--
1.兩邊固定 ,中間自適應
2.當中列要完整顯示
-->
<body>
<div id="left"> left </div>
<div id="middle"> middle </div>
<div id="right"> right </div>
</body>
</html>
三列布局(浮動)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
body{
/*2*left+right*/
min-width: 600px;
}
div{
height: 100px;
}
#left,#right{
width: 200px;
background: pink;
}
#middle{
background: deeppink;
}
#left{
float: left;
}
#right{
float: right;
}
</style>
</head>
<!--
1.兩邊固定 ,中間自適應
2.當中列要完整顯示
3.當中列要優先加載
-->
<body>
<div id="left"> left </div>
<div id="right"> right </div>
<div id="middle"> middle </div>
</body>
</html>
聖盃佈局
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<!--
浮動:搭建完整的佈局框架
margin 爲負值: 調整旁邊兩列的位置(使三列布局到一行上)
使用相對定位:調整旁邊兩列的位置(使兩列位置調整到兩頭)
-->
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.clearfix{
*zoom: 1;
}
.clearfix:after{
content: "";
display: block;
clear: both ;
}
#header,#footer{
height: 20px;
text-align: center;
border: 1px solid deeppink;
background: gray;
}
#content #middle{
background: pink;
float: left;
width: 100%;
}
#content{
padding: 0 200px;
overflow: hidden;
}
#content #middle,#content #left,#content #right{
padding-bottom: 1000px;
margin-bottom: -1000px;
}
#content #left{
position: relative;
left: -200px;
float: left;
margin-left: -100%;
width: 200px;
background: yellow;
}
#content #right{
position: relative;
right: -200px;
float: left;
width: 200px;
margin-left: -200px;
background: yellow;
}
</style>
</head>
<body>
<div id="header"></div>
<div id="content" class="clearfix">
<div id="middle">
<h4>middle</h4>
<h4>middle</h4>
<h4>middle</h4>
<h4>middle</h4>
<h4>middle</h4>
</div>
<div id="left">left</div>
<div id="right">right </div>
</div>
<div id="footer"></div>
</body>
</html>
margin爲負值是一個很常用的方式
僞等高佈局
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#wrap{
width: 750px;
border: 1px solid;
margin: 0 auto;
overflow: hidden;
}
#wrap .left{
float: left;
width: 200px;
background: pink;
padding-bottom: 1000px;
margin-bottom: -1000px;
}
#wrap .right{
float: left;
width: 500px;
background: deeppink;
padding-bottom: 1000px;
margin-bottom: -1000px;
}
.clearfix{
*zoom: 1;
}
.clearfix:after{
content: "";
display: block;
clear: both;
}
</style>
</head>
<body>
<div id="wrap" class="clearfix">
<div class="left">
left <br />
left <br />
left <br />
left <br />
</div>
<div class="right">
right <br />
right <br />
right <br />
right <br />
right <br />
right <br />
right <br />
</div>
</div>
</body>
</html>
雙飛翼佈局
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
/*三列的僞等高佈局*/
#content .middle,#content .left,#content .right{
padding-bottom: 10000px;
margin-bottom: -10000px;
height: 50px;
float: left;
line-height: 50px;
}
#content{
overflow: hidden;
min-width: 600px;
}
/*頭部腳部樣式*/
#header,#footer{
border: 1px solid;
background: gray;
text-align: center;
}
/*雙飛翼佈局*/
#content .middle{
background: green;
width: 100%;
}
#content .left{
margin-left: -100%;
}
#content .right{
margin-left: -200px;
}
#content .left,#content .right{
background: yellow;
width: 200px;
text-align: center;
}
.m_middle{
padding:0 200px;
}
</style>
</head>
<body>
<div id="header">
<h4>header</h4>
</div>
<div id="content">
<div class="middle">
<div class="m_middle">
middle
</div>
</div>
<div class="left"</div>left</div>
<div class="right"</div>right</div>
</div>
<div id="footer">
<h4>footer</h4>
</div>
</body>
</html>
聖盃佈局和雙飛翼佈局
1.兩種佈局方式都是把主列放在文檔流最前面,使主列優先加載
2.這種佈局方式在實現上也有相同之處,都是讓三列浮動,然後通過負外邊矩形形成三列布局
3.兩種佈局方式的不同之處在於如何處理中間主列的位置:
聖盃佈局是利用父容器的左、右內邊距+兩個從從列相對定位
雙飛翼佈局是吧主列嵌套在一個心得的父級塊中利用主列的左、右外邊距進行佈局調整