<div class="box">
<div class="left"></div>
<div class="right"></div>
</div>
- flex布局
.box {
width: 100%;
height: 300px;
border: 1px solid #ccc;
display: flex;
}
.left {
width: 200px;
height: 100%;
background-color: red;
}
.right {
width: 100%;
height: 100%;
background-color:green;
flex: 1;
}
- BFC模式
.box {
width: 100%;
height: 300px;
border: 1px solid #ccc;
}
.left {
width: 200px;
height: 100%;
background-color: red;
float: left;
}
.right {
overflow: hidden; /* 触发bfc */
height: 100%;
background-color:green;
}
- padding-left
.box {
width: 100%;
height: 300px;
border: 1px solid #ccc;
}
.left {
width: 200px;
height: 100%;
background-color: red;
float: left;
}
.right {
width: 100%;
height: 100%;
background-color:green;
padding-left: 200px;
box-sizing: border-box;
}
- margin-left
.box {
width: 100%;
height: 300px;
border: 1px solid #ccc;
}
.left{
float:left;
width:200px;
height:100%;
background:red;
}
.right{
height:100%;
background:green;
margin-left:200px;
}
- table布局
.box {
width: 100%;
height: 300px;
border: 1px solid #ccc;
display: table;
}
.left{
width:200px;
height:100%;
background:red;
display: table-cell;
}
.right{
height:100%;
background:green;
display: table-cell;
}
- calc()
.box {
width: 100%;
height: 300px;
border: 1px solid #ccc;
}
.left{
width:200px;
height:100%;
background:red;
float: left;
}
.right{
height:100%;
background:green;
float: right;
width: calc(100% - 200px);
}
左右定宽中间自适应
1. center在right之后
<div class="box">
<div class="left">left</div>
<div class="right">rigth</div>
<div class="center">center</div>
</div>
.box {
width: 100%;
height: 100%;
}
.left {
float: left;
width: 200px;
height: 100%;
background-color: red;
}
.right {
float: right;
width: 200px;
height: 100%;
background-color: pink;
}
.center {
height: 100%;
background-color: green;
}
2. div顺序正常排列使用flex布局。
网友评论