day07-学成在线
flex布局
弹性盒子换行
弹性盒子可以自动挤压或拉伸,默认情况下,所有弹性盒子都在一行显示。
属性名:flex-wrap
属性值
- wrap:换行
- nowrap:不换行(默认)
小米flex布局
<!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;
}
.mi {
/* 父控子 */
display: flex;
justify-content: space-between;
width: 1226px;
height: 614px;
/* background-color: pink; */
margin: 100px auto;
}
.left {
width: 234px;
height: 614px;
background-color: skyblue;
}
.right {
width: 978px;
height: 614px;
background-color: purple;
}
.right ul {
display: flex;
/* 让li 自动换行 */
flex-wrap: wrap;
/* 主轴两侧对齐 */
justify-content: space-between;
}
.right li {
width: 234px;
height: 300px;
background-color: orange;
list-style: none;
margin-bottom: 14px;
}
</style>
</head>
<body>
<div class="mi">
<div class="left"></div>
<div class="right">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
</div>
</body>
</html>
多行对齐方式
如果有多行侧轴对齐,则去找align-content
如果是单行侧轴对齐,则去找 align-items
属性名:align-content

注意:该属性对单行弹性盒子模型无效。
<!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>
.box {
display: flex;
/* 换行 */
flex-wrap: wrap;
/* 主轴对齐 */
justify-content: space-between;
/* 侧轴单行控制 */
/* align-items: center; */
/* 侧轴多行对齐 */
/* align-content: center; */
align-content: space-between;
width: 1000px;
/* 亲父亲得有高度 */
height: 500px;
border: 3px solid #000;
margin: 100px auto;
}
.box div {
width: 300px;
height: 200px;
background-color: pink;
}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</body>
</html>
修改主轴方向
为什么要修改主轴? 只要父亲添加了display: flex, 所有的子盒子都会一行显示(水平显示) →
但是, 我们很多情况下,需要 盒子垂直竖着显示,此时就需要把主轴修改一下。修改为 竖着 ↓
主轴默认在水平方向,侧轴默认在垂直方向**
属性名:flex-direction

想要如下效果:
代码:
<!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>
.box {
display: flex;
/* 默认主轴是横向 row */
/* 更改主轴的方向 我想要1和2盒子竖着排列 */
flex-direction: column;
width: 300px;
height: 300px;
border: 1px solid #000;
/* 主轴 */
justify-content: center;
/* 侧轴 */
align-items: center;
}
.box div {
width: 100px;
height: 100px;
background-color: pink;
}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
</div>
</body>
</html>
弹性伸缩比
作用:控制弹性盒子的主轴方向的尺寸。
属性名:flex
属性值:整数数字,表示占用父级剩余尺寸的份数。
<!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>
.box {
display: flex;
width: 80%;
height: 200px;
border: 1px solid #000;
}
.box span {
/* 不会区分原来属于什么模式 */
/* width: 100px;
height: 100px;
background-color: pink; */
flex: 1;
background-color: pink;
}
/* 圣杯布局两侧固定,中间自适应 */
.left,
.right {
width: 100px;
background-color: skyblue;
}
.center {
flex: 1;
background-color: purple;
}
.center1 {
flex: 2;
background-color: pink;
}
</style>
</head>
<body>
<div class="box">
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
</div>
<div class="box">
<div class="left">左</div>
<div class="center">中</div>
<div class="center1">中</div>
<div class="right">右</div>
</div>
</body>
</html>
01-项目目录
网站根目录是指存放网站的第一层文件夹,内部包含当前网站的所有素材,包含 HTML、CSS、图片、JavaScript等等。

- 首页引入CSS文件
<!-- 顺序要求:先清除再设置 -->
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/index.css">
02-版心居中

.wrapper {
margin: 0 auto;
width: 1200px;
}
body {
background-color: #f3f5f7;
}
03-布局思路
- 布局思路:先整体再局部,从外到内,从上到下,从左到右
- CSS 实 现思路
- 画盒子,调整盒子范围 → 宽高背景色
- 调整盒子位置 → flex 布局、内外边距
- 控制图片、文字内容样式
04-header区域-整体布局

HTML结构
<!-- 头部区域 -->
<div class="header">
<div class="wrapper">
<!-- logo -->
<div class="logo">logo</div>
<!-- 导航 -->
<div class="nav">导航</div>
<!-- 搜索 -->
<div class="search">search</div>
<!-- 用户 -->
<div class="user">用户</div>
</div>
</div>
CSS样式
/* 头部区域 */
.header {
height: 100px;
background-color: #fff;
}
.header .wrapper {
padding-top: 29px;
display: flex;
}
05-header区域-logo

logo 功能:
- 单击跳转到首页
- 搜索引擎优化:提升网站百度搜索排名
实现方法:
- 标签结构:h1 > a > 网站名称(搜索关键字)
<div class="logo">
<h1><a href="#" title="学成在线">学成在线</a></h1>
</div>
- CSS 样式
/* logo */
.logo a {
display: block;
width: 195px;
height: 41px;
background-image: url(../images/logo.png);
font-size: 0;
}
06-header区域-导航
实现方法:
- 标签结构:ul > li * 3 > a
- 优势:避免堆砌 a 标签,网站搜索排名降级

HTML结构
<!-- nav 导航 -->
<div class="nav">
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">课程</a></li>
<li><a href="#">职业规划</a></li>
</ul>
</div>
CSS样式
/* nav导航 */
.nav {
margin-left: 100px;
}
.nav ul {
display: flex;
}
.nav li {
margin-right: 20px;
}
.nav li a {
font-size: 19px;
padding: 8px;
line-height: 34px;
}
.nav li a:hover {
border-bottom: 2px solid #00a4ff;
}
07-header区域-搜索布局
HTML结构
<div class="search"></div>
CSS样式
/* 搜索 */
.search {
width: 412px;
height: 40px;
background-color: #f3f5f7;
border-radius: 20px;
margin-left: 80px;
}
08-header区域-搜索内容
HTML结构
<!-- search 搜索 -->
<div class="search">
<input type="search" placeholder="输入关键词">
</div>
CSS样式
.search input {
width: 412px;
height: 40px;
/* 背景色透明 */
background-color: transparent;
/* 自带边框为0不显示 */
border: 0;
padding-left: 20px;
padding-right: 30px;
/* 去掉点击之后显示的黑色边框 */
outline: 0;
}
09-header区域-用户区域

HTML结构
<div class="user">
<a href="#">
<img src="./uploads/user.png" alt="">
<span>播仔学前端</span>
</a>
</div>
CSS样式
/* 用户模块 */
.user {
margin-left: 32px;
}
.user img {
/* 让文字和图片垂直居中对齐 */
vertical-align: middle;
}
.user span {
color: #666666;
}
10-banner区域-布局

HTML结构
<div class="banner">
<div class="wrapper">
<div class="left">left</div>
<div class="right">right</div>
</div>
</div>
CSS样式
/* header盒子制作结束啦 */
/* banner开始 */
.banner {
height: 420px;
background-color: #0092cb;
}
.banner .wrapper {
height: 420px;
background: url(../uploads/banner.png);
}
.banner .wrapper {
display: flex;
/* 主轴两侧对齐 */
justify-content: space-between;
/* 侧轴居中 */
align-items: center;
}
.banner .left {
width: 191px;
height: 420px;
/*背景半透明*/
background-color: rgba(0, 0, 0, 0.42);
}
.banner .right {
width: 218px;
height: 305px;
background-color: pink;
}
11-banner区域-侧导航
HTML结构
<div class="left">
<ul>
<li><a href="#">前端开发</a></li>
<li><a href="#">后端开发</a></li>
<li><a href="#">移动开发</a></li>
<li><a href="#">人工智能</a></li>
<li><a href="#">商业预测</a></li>
<li><a href="#">云计算&大数据</a></li>
<li><a href="#">运维&测试</a></li>
<li><a href="#">UI设计</a></li>
<li><a href="#">产品</a></li>
</ul>
</div>
CSS样式
/* 侧导航 */
.banner .left {
padding: 3px 20px;
width: 191px;
height: 420px;
background-color: rgba(0,0,0,0.42);
}
.banner .left a {
/* 块级:宽度是父级的100% */
display: block;
height: 46px;
background: url(../images/right.png) no-repeat right center;
line-height: 46px;
font-size: 16px;
color: #fff;
}
.banner .left a:hover {
background-image: url(../images/right-hover.png);
color: #00a4ff;
}
12-banner区域-课程表布局

HTML布局
<div class="right">
<h3>我的课程表</h3>
<div class="content">1</div>
</div>
CSS样式
/* 课程表 */
.banner .right {
margin-top: 60px;
width: 218px;
height: 305px;
background-color: #209dd5;
border-radius: 10px;
}
.banner .right h3 {
margin-left: 14px;
height: 48px;
line-height: 48px;
font-size: 15px;
color: #fff;
font-weight: 400;
}
.banner .right .content {
padding: 14px;
height: 257px;
background-color: #fff;
border-radius: 10px;
}
13-banner区域-课程表内容
HTML结构
<dl>
<dt>数据可视化课程</dt>
<dd><span>正在学习</span>-<strong>echarts使用步骤</strong></dd>
</dl>
<dl>
<dt>Vue3医疗项目课程 </dt>
<dd><span>正在学习</span>-<strong>认识组合式API</strong></dd>
</dl>
<dl>
<dt>React核心技术课程</dt>
<dd><span>正在学习</span>-<strong>rudex配合TS使用</strong></dd>
</dl>
CSS样式
.banner .right dl {
margin-bottom: 12px;
border-bottom: 1px solid #e0e0e0;
}
.banner .right dt {
margin-bottom: 8px;
font-size: 14px;
line-height: 20px;
font-weight: 700;
}
.banner .right dd {
margin-bottom: 8px;
font-size: 12px;
line-height: 16px;
}
.banner .right dd span {
color: #00a4ff;
}
.banner .right dd strong {
color: #7d7d7d;
font-weight: 400;
}
14-banner区域-全部课程
HTML结构
<a href="#">全部课程</a>
CSS样式
.banner .right a {
display: block;
height: 32px;
background-color: #00a4ff;
text-align: center;
line-height: 32px;
font-size: 14px;
color: #fff;
border-radius: 15px;
}
15-精品推荐-区域布局

HTML结构
<!-- 精品推荐 -->
<div class="recommend wrapper">
<h3>精品推荐</h3>
<ul>
<li><a href="#">HTML</a></li>
</ul>
<a href="#" class="modify">修改兴趣</a>
</div
CSS样式
/* 精品推荐 */
.recommend {
display: flex;
margin-top: 11px;
padding: 0 20px;
height: 60px;
background-color: #fff;
box-shadow: 0px 1px 2px 0px rgba(211, 211, 211, 0.5);
line-height: 60px;
}