前期准备
<body>
<div class="left"></div>
<div class="right"></div>
</body>
方法一:float
.left {
float: left;
width: 100px;
height: 200px;
background-color: red;
}
.right {
margin-left: 100px;
height: 200px;
color: white;
background-color: blue;
}
方法二:absolute
body {
position: relative;
}
.left {
width: 100px;
height: 200px;
background-color: red;
}
.right {
position: absolute;
top: 0;
left: 100px;
width: calc(100% - 100px); /*calc中运算符符号的前后都需要空格*/
height: 200px;
color: white;
background-color: blue;
}
方法三:flex
body {
display: flex;
}
.left {
width: 100px;
height: 200px;
background-color: red;
}
.right {
flex: 1; /*flex-grow:1; flex-shrink:1; flex-basis:0%*/
color: #fff;
background-color: blue;
}