1、左边左浮动,margin-left负值,右边右浮动
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.left{
float: left;
width: 100%;
height: 300px;
background: #000;
margin-right: -200px;
font-size: 40px;
color: #fff;
}
.right{
float: right;
width: 200px;
background: red;
height: 300px;
font-size: 40px;
color: #fff;
}
</style>
</head>
<body>
<div class="box">
<div class="left">left</div>
<div class="right">right</div>
</div>
</body>
</html>
2、右边绝对定位,左边margin-left
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.left{
height: 300px;
background: #000;
margin-right: 200px;
font-size: 40px;
color: #fff;
}
.right{
position: absolute;
top: 0;
right: 0;
width: 200px;
background: red;
height: 300px;
font-size: 40px;
color: #fff;
}
</style>
</head>
<body>
<div class="box">
<div class="left">left</div>
<div class="right">right</div>
</div>
</body>
</html>
3、左右绝对定位,左边加width,top,right,left
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.left{
position: absolute;
top: 0;
right: 0;
left: 0;
width: 100%;
background: #000;
height: 300px;
font-size: 40px;
color: #fff;
}
.right{
position: absolute;
top: 0;
right: 0;
width: 200px;
background: red;
height: 300px;
font-size: 40px;
color: #fff;
}
</style>
</head>
<body>
<div class="box">
<div class="left">left</div>
<div class="right">right</div>
</div>
</body>
</html>