浮动法
<style type="text/css">
html,body{
height: 100%;
margin: 0;
}
div{
height: 100%;
}
.left{
background-color: red;
float: left;
width: 300px;
}
.right{
background-color: yellow;
float: right;
width: 300px;
}
.center{
background-color: green;
margin-left: 300px;
margin-right: 300px;
}
</style>
<body>
<div class="left">left</div>
<div class="right">right</div>
<div class="center">center</div>
</body>
定位法
<style type="text/css">
html,body{
height: 100%;
margin: 0;
}
div{
height: 100%;
}
.parent{
position: relative;
}
.left{
background-color: red;
width: 300px;
position: absolute;
left: 0;
}
.right{
background-color: yellow;
width: 300px;
position: absolute;
right: 0;
}
.center{
background-color: green;
margin-left: 300px;
margin-right: 300px;
}
</style>
<body>
<div class="parent">
<div class="left">left</div>
<div class="right">right</div>
<div class="center">center</div>
</div>
</body>
弹性盒子法
<style type="text/css">
html,body{
height: 100%;
margin: 0;
}
div{
height: 100%;
}
.parent{
display: flex;
}
.left{
width: 300px;
background-color: red;
}
.right{
width: 300px;
background-color: yellow;
}
.center{
flex-grow:1;
background-color: green;
}
</style>
<body>
<div class="parent">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
</body>
网格布局
<style type="text/css">
html,body{
height: 100%;
margin: 0;
}
div{
height: 100%;
}
.parent{
display: grid;
grid-template-columns: 300px auto 300px;
}
.left{
background-color: red;
}
.right{
background-color: yellow;
}
.center{
background-color: green;
}
</style>
<body>
<div class="parent">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
</body>
表格布局
<style>
body,html{
height: 100%;
margin: 0;
}
div{
height: 100%;
}
.parent{
width: 100%;
display: table;
}
.right{
width: 300px;
background-color: red;
display: table-cell;
}
.left{
width: 300px;
background-color: blue;
display: table-cell;
}
.center{
background-color: yellow;
display: table-cell;
}
</style>
<body>
<div class="parent">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
</body>
双飞翼
<style>
html,body{
height: 100%;
margin: 0;
}
div{
height: 100%;
}
.center{
width: 100%;
float: left;
}
.main{
background-color: blueviolet;
margin-left: 300px;
margin-right: 300px;
}
.left{
background-color: cornflowerblue;
width: 300px;
float: left;
margin-left: -100%;
}
.right{
background-color: #ff0097;
width: 300px;
float: left;
margin-left: -300px;
}
</style>
<body>
<div class="center">
<div class="main">center</div>
</div>
<div class="left">left</div>
<div class="right">right</div>
</body>
圣杯
<style>
body,html{
height: 100%;
margin: 0;
}
div{
height: 100%;
}
.parent{
padding-left: 300px;
padding-right: 300px;
}
.right{
background-color: red;
width: 300px;
float: left;
margin-left: -300px;
position: relative;
right: -300px;
}
.left{
background-color: blue;
width: 300px;
float: left;
margin-left: -100%;
position: relative;
left: -300px;
}
.center{
background-color: yellow;
width: 100%;
float: left;
}
</style>
<body>
<div class="parent">
<div class="center">center</div>
<div class="left">left</div>
<div class="right">right</div>
</div>
</body>