左右侧固定实现都是一样道理的
前3种方式统一布局:
<body>
<div class="left"></div>
<div class="right"></div>
</body>
1、float:
右侧固定,左侧自由伸缩。效果图:
![在这里插入图片描述](https://img-blog.csdnimg.cn/ded28f0fff594d3f9eb418255e4a69f1.png)
* {
padding: 0;
margin: 0;
}
.left {
float: right;
width: 100px;
height: 100px;
background-color: transparent;
}
.right {
height: 100px;
margin-right: 100px;
background-color: burlywood;
}
2、position:
右侧固定,左侧自由伸缩。效果图:
![在这里插入图片描述](https://img-blog.csdnimg.cn/39e0005f783946f9b1c5a599f51161bd.png)
* {
margin: 0;
padding: 0;
}
.left {
position: absolute;
right: 0;
width: 100px;
height: 100px;
background-color: red;
}
.right {
height: 100px;
background-color: tomato;
margin-right: 100px;
}
3、bfc:
左侧固定,右侧自由伸缩。效果图:
![在这里插入图片描述](https://img-blog.csdnimg.cn/f7f672a59d6a425f94d958314b2f5f79.png)
* {
padding: 0;
margin: 0;
}
.left {
float: left;
width: 100px;
height: 100px;
background-color: transparent;
}
.right {
height: 100px;
overflow: hidden;
background-color: crimson;
}
4、flex:
左侧固定,右侧自由伸缩。效果图:
![在这里插入图片描述](https://img-blog.csdnimg.cn/5cebcfb38fd54a389bc801b00e9f6056.png)
布局:
<body>
<div class="box">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
css:
.box {
display: flex;
}
.right {
flex: 1;
height: 100px;
background-color: blanchedalmond;
}
.left {
width: 100px;
height: 100px;
background-color: transparent;
}