第一种方法:绝对定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin:0;
padding:0;
}
.box{
position: relative;
}
#left,#center,#right{
height: 300px;
}
#left{
position: absolute;
top:0;
left:0;
width: 100px;
background-color: pink;
}
#center{
position: absolute;
top:0;
left:100px;
right:100px;
bottom:0;
background-color: red;
}
#right{
position: absolute;
top:0;
right: 0;
width: 100px;
background-color: blue;
}
</style>
</head>
<body>
<div class="box">
<div id="left"></div>
<div id="center"></div>
<div id="right"></div>
</div>
</body>
</html>
第二种方法:flex布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin:0;
padding:0;
}
.box{
display: flex;
}
#left{
background-color: pink;
height: 300px;
width: 100px;
}
#center{
background-color: red;
height: 300px;
flex:1;
}
#right{
background-color: blue;
height: 300px;
width: 100px;
}
</style>
</head>
<body>
<div class="box">
<div id="left"></div>
<div id="center"></div>
<div id="right"></div>
</div>
</body>
</html>
第三种方法:浮动
必须是center放在最后
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin:0;
padding:0;
}
#left,#center,#right{
height: 300px;
}
#left{
float: left;
width: 100px;
background-color: pink;
}
#right{
float: right;
width: 100px;
background-color:blue;
}
#center{
margin-left: 100px;
margin-right: 100px;
background-color: red;
}
</style>
</head>
<body>
<div id="left"></div>
<div id="right"></div>
<div id="center"></div>
</body>
</html>