HTML部分:
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="./index.css" />
<title>Flex 布局title>
head>
<body>
<ul>
<li>
<img src="https://qgt-document.oss-cn-beijing.aliyuncs.com/new-learn-path/123.png_620x10000q90.jpg" alt="">
<div class="text">Coursediv>
li>
<li>
<img src="https://qgt-document.oss-cn-beijing.aliyuncs.com/new-learn-path/%E4%BC%9A%E5%91%98%E4%B8%93%E4%BA%AB.png" alt="">
<div class="text">会员div>
li>
<li>
<img src="https://qgt-document.oss-cn-beijing.aliyuncs.com/new-learn-path/%E7%A6%8F%E5%88%A9%E5%9B%BE%E6%A0%87.png" alt="">
<div class="text">活动福利div>
li>
<li>
<img src="https://qgt-document.oss-cn-beijing.aliyuncs.com/new-learn-path/web.png" alt="">
<div class="text">前端div>
li>
ul>
body>
html>
CSS部分:
/* css reset */
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
ul {
background: #ffffff;
padding: 10px;
display: flex;
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
justify-content: space-between; /*调整水平方向的分布justify-content*/
/*justify-content有六个有效值:
flex-start:项目向水平方向起点对齐;
space-between在每行上均匀分配项目,相邻项目间距离相同;
flex-end项目向水平方向的终点对齐;
spac-around在每行均匀分配项目;
center项目在水平方向上居中;
space-evenly在每行上均匀分配项目,各项目间距相同。
*/
height:130px; /*设置导航条固定高度,可以看到,图片和文字没有在垂直方向上居中*/
}
ul li {
margin: 0 10px;
font-size: 14px;
text-align: center;
}
ul li > img {
width: 50px;
height: 50px;
}