- BFC(块格式化上下文) -- 左边定宽float浮动,右边overflow
// html部分:
<div class="container">
<div class="leftDiv">左边</div>
<div class="rightDiv">右边</div>
</div>
// css部分:
html,
body {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
}
.leftDiv {
width: 300px;
height: 100%;
float: left;
background-color: brown;
}
.rightDiv {
width: auto;
height: 100%;
background-color: aquamarine;
overflow: hidden;
}
- float + margin --- 左侧float浮动,右侧外边距
// 其他部分同上
// css部分-rightDiv:
.rightDiv {
width: auto;
height: 100%;
background-color: aquamarine;
margin-left: 300px;
}
- position + margin --- 左侧绝对定位,右侧外边距
// 其他部分同第一个
// css部分- container、leftDiv、rightDiv:
.container {
width: 100%;
height: 100%;
position: relative;
}
.leftDiv {
width: 300px;
height: 100%;
background-color: brown;
position: absolute;
left: 0;
top: 0;
}
.rightDiv {
width: auto;
height: 100%;
background-color: aquamarine;
margin-left: 300px;
}
- flex布局
// 其他部分同第一个
// css部分- container、leftDiv、rightDiv:
.container {
width: 100%;
height: 100%;
display: -webkit-box;
/* 老版本语法: Safari, iOS, Android browser, older WebKit browsers. */
display: -moz-box;
/* 老版本语法: Firefox (buggy) */
display: -ms-flexbox;
/* 混合版本语法: IE 10 */
display: -webkit-flex;
/* 新版本语法: Chrome 21+ */
display: flex;
/* 新版本语法: Opera 12.1, Firefox 22+ */
}
.leftDiv {
width: 300px;
height: 100%;
background-color: brown;
}
.rightDiv {
width: auto;
height: 100%;
background-color: aquamarine;
-webkit-flex: 1;
/* Chrome */
-ms-flex: 1;
/* IE 10 */
flex: 1;
/* NEW, Spec - Opera 12.1, Firefox 20+ */
-webkit-box-flex: 1;
/* OLD - iOS 6-, Safari 3.1-6 */
-moz-box-flex: 1;
/* OLD - Firefox 19- */
}
- float + calc() 函数
// 其他部分同第一个
// css部分- container、leftDiv、rightDiv:
.container {
width: 100%;
height: 100%;
}
.leftDiv {
width: 300px;
height: 100%;
background-color: brown;
float: left;
}
.rightDiv {
width: calc(100% - 300px);
float: right;
height: 100%;
background-color: aquamarine;
}
- display: table
// 其他部分同第一个
// css部分- container、leftDiv、rightDiv:
.container {
width: 100%;
height: 100%;
display: table;
}
.leftDiv {
width: 300px;
height: 100%;
background-color: brown;
display: table-cell;
}
.rightDiv {
height: 100%;
background-color: aquamarine;
display: table-cell;
}