如何实现:页面两栏布局左侧固定、右侧自适应

715 阅读1分钟
<div class="box">
   <div class="inner_box_left">1</div>
   <div class="inner_box_right">2</div>
</div>

方法一:利用flex布局

.box{
    display: flex;
}
.inner_box_left{
	width:100px;
	background-color:green;
}
.inner_box_right{
	flex: 1 0 auto;//或者直接给auto,相当于flex: 1 1 auto;
	background-color:red;
}

方法二:利用左侧float+右侧margin

.inner_box_left{
    width: 100px;
    float: left;
    background-color: green;
}
.inner_box_right{
    background-color: red;
    margin-left:100px;
}

方法三:利用左侧float+右侧float+右侧calc宽度

.inner_box_left{
    width: 100px;
    float: left;
    background-color: green;
}
.inner_box_right{
    background-color: red;
    float: right;
    width:calc(100% - 100px);
}

方法四:利用左侧float+右侧overflow

.inner_box_left{
    width: 100px;
    float: left;
    background-color: green;
}
.inner_box_right{
    background-color: red;
    overflow:hidden;
}