布局
<div id="root">
<div class="left"></div>
<div class="right"></div>
</div>
1. float浮动
<!-- 样式 -->
<style>
#root {
width: 800px;
height: 500px;
background-color: #ccc;
}
.left {
float: left;
width: 200px;
height: 500px;
background-color: pink;
}
.right {
height: 500px;
margin-left: 200px;
background-color: #3cd;
}
</style>
2. flex布局
父元素设置display flex
左元素设置flex-basis
右元素设置flex-grow或flex为1
<style>
#root {
display: flex;
width: 800px;
height: 500px;
background-color: #ccc;
}
.left {
flex-basis: 200px;
height: 500px;
background-color: pink;
}
.right {
flex-grow: 1;
height: 500px;
background-color: #3cd;
}
</style>
3. flex和min-width
<style>
#root {
display: flex;
width: 800px;
height: 500px;
background-color: #ccc;
}
.left {
min-width: 200px;
height: 500px;
background-color: pink;
}
.right {
width: 100%;
height: 500px;
background-color: #3cd;
}
</style>
只有设置min-width才可以使用width:100%