一、浮动
二、flex布局
三、绝对定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.left {
float: left;
width: 300px;
background-color: rebeccapurple;
}
.right {
background-color: rgb(206, 65, 225);
}
.main1 {
display: flex;
}
.left1 {
width: 300px;
flex-shrink: 0;
flex-grow: 0;
background-color: rgb(153, 129, 51);
}
.right1 {
flex: 1;
background-color: royalblue;
}
/* 第三种 */
.main2 {
position: relative;
width: 100%;
}
.left2 {
position: absolute;
width: 300px;
left: 0;
background-color: rgb(51, 153, 97);
}
.right2 {
position: absolute;
right: 0;
left: 300px;
background-color: rgb(166, 65, 225);
}
</style>
</head>
<body>
<div class="main">
<div class="left">左边</div>
<div class="right">右边</div>
</div>
<div class="main1">
<div class="left1">左边</div>
<div class="right1">右边</div>
</div>
<div class="main2">
<div class="left2">左边</div>
<div class="right2">右边</div>
</div>
</body>
</html>