0 前言
记录前端学习~
1 小米模块案例
目标样式
代码
代码框架
test.html
<!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-sizing: border-box;
}
.box {
display: flex;
justify-content: space-between;
margin: 100px auto;
width: 1226px;
height: 615px;
}
.left {
width: 234px;
height: 615px;
background-color: #800080;
}
.right {
width: 978px;
height: 615px;
}
.right ul {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.right li {
list-style: none;
margin-bottom: 14px;
width: 234px;
height: 300px;
background-color: skyblue;
}
.right li:nth-child(n+4) {
margin-bottom: 0;
}
</style>
</head>
<body>
<div class="box">
<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>
2 网页导航案例
目标样式
代码
代码框架
test.html
<!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-sizing: border-box;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
.nav ul {
display: flex;
}
.nav li {
width: 80px;
height: 50px;
text-align: center;
}
.nav li a {
display: inline-block;
width: 80px;
height: 50px;
background-color: pink;
line-height: 50px;
font-size: 16px;
color: #fff;
}
.nav li a:hover {
background-color: #008000;
}
</style>
</head>
<body>
<div class="nav">
<ul>
<li><a href="#">新闻1</a></li>
<li><a href="#">新闻2</a></li>
<li><a href="#">新闻3</a></li>
<li><a href="#">新闻4</a></li>
<li><a href="#">新闻5</a></li>
<li><a href="#">新闻6</a></li>
<li><a href="#">新闻7</a></li>
<li><a href="#">新闻8</a></li>
</ul>
</div>
</body>
</html>
总结
- flex-wrap 属性指定 flex 元素单行显示还是多行显示(wrap)
- :nth-child(n+4) 表示从第四个元素开始