美文网首页
左定宽右自适应

左定宽右自适应

作者: 一蓑烟雨任平生_cui | 来源:发表于2018-06-13 11:22 被阅读0次
<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布局。

相关文章

网友评论

      本文标题:左定宽右自适应

      本文链接:https://www.haomeiwen.com/subject/ssfjeftx.html