1.浮动方案
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.left {
float: left;
height: 200px;
width: 200px;
background-color: red;
}
.right {
width: 200px;
height: 200px;
background-color: blue;
float: right;
}
.main {
margin-left: 220px;
margin-right: 220px;
height: 200px;
background-color: green;
}
</style>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="right"></div>
<div class="main"></div>
</div>
</body>
</html>
2.绝对定位
<!DOCTYPE html>
<html lang="en">
<head>
<style>
*{
padding:0px;
margin:0px;
}
.main {
height: 200px;
margin: 0px 200px;
background-color: green;
}
.left {
position: absolute;
width: 200px;
height: 200px;
left: 0;
top:0;
background-color: red;
}
.right {
position: absolute;
width: 200px;
height: 200px;
right: 0;
top:0;
background-color: blue;
}
</style>
</head>
<body>
<div class="container">
<div class="main"></div>
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
3.flex
<!DOCTYPE html>
<html lang="en">
<head>
<style>
*{
margin:0px;
padding:0px;
}
.container{
display:flex;
}
.main{
flex:1;
height:200px;
background-color:red;
}
.left{
width:200px;
height:200px;
background-color: green;
}
.right{
width:200px;
height:200px;
background-color:yellow;
}
</style>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="main"></div>
<div class="right"></div>
</div>
</body>
</html>
4.grid布局
<!DOCTYPE html>
<html lang="en">
<head>
<style>
*{
margin:0px;
padding:0px;
}
.container{
display:grid;
grid-template-rows:200px;
grid-template-columns:200px auto 200px;
}
.main{
height:200px;
background-color:red;
}
.left{
height:200px;
background-color: green;
}
.right{
height:200px;
background-color:yellow;
}
</style>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="main"></div>
<div class="right"></div>
</div>
</body>
</html>
5.table布局
<!DOCTYPE html>
<html lang="en">
<head>
<style>
*{
margin:0px;
padding:0px;
}
.container{
display:table;
width:100%;
}
.main{
display:table-cell;
background-color:red;
}
.left{
display:table-cell;
height:200px;
width:200px;
background-color: green;
}
.right{
display:table-cell;
height:200px;
width:200px;
background-color:yellow;
}
</style>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="main"></div>
<div class="right"></div>
</div>
</body>
</html>