flex布局四个div盒子前三个盒子左对齐,后面的盒子右对齐

发布时间 2023-07-04 10:31:02作者: 小猴子会上树

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>flex布局</title>
<style>
*{
margin: 0;
padding: 0;
}
.box {
display: flex;
justify-content: flex-start;
}

.block {
width: 100px;
height: 100px;
border:1px solid black;

}
</style>
</head>
<body>
<div class="box">
<div class="block">块1</div>
<div class="block">块2</div>
// 此地margin-left:auto;自动填充了剩余空间
<div class="block" style="margin-left: auto;">块3</div>
<div class="block">块4</div>
</div>
</body>
</html>