效果图:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
width: 1226px;
height: 615px;
background-color: rgb(116, 78, 78);
margin: 0 auto;
}
.left {
width: 234px;
height: 615px;
background-color: skyblue;
float: left;
}
.right {
width: 992px;
height: 615px;
background-color: purple;
float: left;
}
/* 这里为什么要是这个选择器呢?是为了防止在后代div里还有div,所以不用后代选择器 */
.right>div {
width: 234px;
height: 300px;
background-color:rgb(151, 87, 98);
float: left;
margin-left: 14px;
margin-bottom: 14px;
}
</style>
</head>
<body>
<div class="box">
<div class="left">
Left
</div>
<div class="right">
<!-- 这里也可以用列表 -->
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
</div>
</body>
</html>
在这里遇到一问题:margin好像不会把盒子撑大,而且浮动体只有超过父级的左右边框才会换行。