用《CSS浮动》文章里的内容完成布局案例二
效果图
代码实现
<!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;
}
.con {
width: 1226px;
height: 614px;
/* background-color: rgb(214, 86, 171); */
margin: 20px auto;
}
.left{
float: left;
width: 234px;
height: 614px;
background-color: #800080;
}
.right{
float: right;
width: 978px;
height: 614px;
/* background-color: #204655; */
}
.right ul{
list-style: none;
}
.right li{
float: left;
margin-right: 14px;
margin-bottom: 14px;
width: 234px;
height: 300px;
background-color: #87ceeb;
}
/* 如果父级宽度不够,子级会自动换行 */
.right li:nth-child(4n){
margin-right: 0;
}
</style>
</head>
<body>
<div class="con">
<div class="left"></div>
<div class="right">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
</body>
</html>