实现方式:
- flex 布局
- position
- float 布局
- table
- gird 网格
html代码:
<div class="main">
<div class="left"></div>
<div class="right"></div>
</div>
第一种:flex布局
<style>
.main{
display: flex;
}
.left,.right{
height: 100px;
}
.left{
width: 200px;
background: red;
}
.right{
flex: 1;
background: blue;
}
</style>
第二种:position
<style>
.main{
position: relative;
}
.left,.right{
height: 100px;
}
.left{
width: 200px;
background: red;
}
.right{
position: absolute;
top: 0;
right: 0;
left: 200px;
background: blue;
}
</style>
第三种:float布局
1、利用margin-left
<style>
.left,.right{
height: 200px;
}
.left{
float: left;
width: 200px;
background: red;
}
.right{
margin-left: 200px;
background: blue;
}
</style>
2、利用overflow:hidden
<style>
.left,.right{
height: 200px;
}
.left{
float: left;
width: 200px;
background: red;
}
.right{
overflow: hidden;
background: blue;
}
</style>
第四种:table
<style>
.main{
display: table;
width: 100%;
}
.left,.right{
display: table-cell;
height: 100px;
}
.left{
width: 200px;
background: red;
}
.right{
background: blue;
}
</style>
第五种:gird网格
<style>
.main{
width: 100%;
height: 100px;
display: grid;
grid-template-columns: 200px auto; /*设置每一列的宽度,左200px,右自适应*/
}
.left{
background: red;
}
.right{
background: blue;
}
</style>