未设置时原布局效果,div垂直排列
方法一:浮动
<style>
.con{width: 100%; }
.con>div{height: 500px; }
.left{width:20%;float:left;background-color: pink; }
.center{ width: 60%;float: left;background-color: yellowgreen;}
.right{width:20%;float:left;background-color: skyblue;}
</style>
<body>
<div class="con">
<div class="left">左</div>
<div class="center">中</div>
<div class="right">右</div>
</div>
</body>
方法二:绝对定位
<style>
.con{ width: 100%; }
.con>div{height: 500px; }
.left{
position:absolute;
top: 0px;
left: 0px;
width:20%;
background-color: pink; }
.center{
position:absolute;
top: 0px;
left: 20%;
width: 60%;
background-color: yellowgreen;}
.right{
position:absolute;
top: 0px;
left: 80%;
width:20%;
background-color: skyblue;}
</style>
<body>
<div class="con">
<div class="left">左</div>
<div class="center">中</div>
<div class="right">右</div>
</div>
</body>
方法三:Flex布局
<style>
.con{
display: flex;
width: 100%;
}
.con>div{height: 500px; }
.left{
width:20%;
background-color: pink; }
.center{
width: 60%;
background-color: yellowgreen;}
.right{
width:20%;
background-color: skyblue;}
</style>
<body>
<div class="con">
<div class="left">左</div>
<div class="center">中</div>
<div class="right">右</div>
</div>
</body>
方法四:table布局
<style>
.con{
width: 100%;
}
.con>div{height: 500px; }
.left{
display: table-cell;
width:200px;
background-color: pink; }
.center{
display: table-cell;
width: 600px;
background-color: yellowgreen;}
.right{
display: table-cell;
width:200px;
background-color: skyblue;}
</style>
<div class="con">
<div class="left">左</div>
<div class="center">中</div>
<div class="right">右</div>
</div>