左定宽右自适应

2018-06-13  本文已影响0人  一蓑烟雨任平生_cui
<div class="box">
    <div class="left"></div>
    <div class="right"></div>
</div>
  1. 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;
}
  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;
}
  1. 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;
}
  1. 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;
}
  1. 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;
}
  1. 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布局。
上一篇下一篇

猜你喜欢

热点阅读