系统性的总结归纳是非常有必要的,不然这么多css,很容易搞混淆以致于走火入魔
(1)使用absolute+margin
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
html,body{margin: 0;height: 100%;}
/*不加html会出现中间内容区域高度塌陷*/
.left, .right{
position: absolute;
top: 0;
height: 100%;
width: 200px;
}
.left{left: 0;background-color: #FF8C00;}
.right{right: 0;background-color: lightpink;}
.main{margin: 0 210px;background-color: #1E90FF;height:100%;}
</style>
</head>
<body>
<div class="left">我是左边部分</div>
<div class="right">我是右边部分</div>
<div class="main">我是内容部分</div>
</body>
</html>
(2)margin负值
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
html,body{margin: 0;height: 100%;}
/*不加html会出现中间内容区域高度塌陷*/
.left, .right{
float: left;
height: 100%;
width: 200px;
}
.left{background-color: #FF8C00;margin-left: -100%;}
.right{background-color: lightpink;margin-left: -200px;}
.far-box{width: 100%;height: 100%;float: left;}
.son-box{margin: 0 210px;background-color: #1E90FF;height:100%;}
</style>
</head>
<body>
<div class="far-box">
<div class="son-box">我是内容部分</div>
</div>
<div class="left">我是左边部分</div>
<div class="right">我是右边部分</div>
</body>
</html>
(3)左右边栏float
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
html,body{margin: 0;height: 100%;}
.left, .right{
height: 100%;
width: 200px;
}
.left{background-color: #FF8C00;float: left;}
.right{background-color: lightpink;float: right;}
.main{margin: 0 210px;height: 100%;background-color: #FF0000;}
</style>
</head>
<body>
<div class="left">我是左边部分</div>
<div class="right">我是右边部分</div>
<div class="main">我是内容部分</div>
</body>
</html>