01-导读/目标
02-emmet语法
Emmet语法的前身是Zencoding,它使用缩写,来提高html/css的编写速度, Vscode内部已经集成该语法。
1.快速生成HTML结构语法
2.快速生成CSS样式语法
1.快速生成HTML语法结构
--------练习
<body>
<!-- 直接输入div 回车/tab键 -->
<div></div>
<!-- 生成多个相同标签 div*3 回车/tab -->
<div></div>
<div></div>
<div></div>
<!-- 父子级关系 使用> 回车/tab键 -->
<!-- ul>li -->
<ul>
<li></li>
</ul>
<!-- div>span -->
<div><span></span></div>
<!-- 兄弟关系 使用+ 回车/tab键 -->
<!-- div+p -->
<div></div>
<p></p>
<!-- h1+p -->
<h1></h1>
<p></p>
<!-- 生成带有类名或id名的 .demo 或 #two 回车/tab键 -->
<!-- .size -->
<div class="size"></div>
<!-- p.color -->
<p class="color"></p>
<!-- #two -->
<div id="two"></div>
<!-- p#two -->
<p id="two"></p>
<!-- 生成div类名是有顺序的 使用自增符号$ 回车/tab键 -->
<!-- div$*3 -->
<div1></div1>
<div2></div2>
<div3></div3>
<!-- ul>li$*3 -->
<ul>
<li1></li1>
<li2></li2>
<li3></li3>
</ul>
<!-- .demo$*3 -->
<div class="demo1"></div>
<div class="demo2"></div>
<div class="demo3"></div>
<!-- 在生成的标签内部写内容 使用{} 回车/tab键 -->
<!-- div{我爱学习} -->
<div>我爱学习</div>
<!-- div{我爱美食}*3 -->
<div>我爱美食</div>
<div>我爱美食</div>
<div>我爱美食</div>
<!-- div{$}*3 -->
<div>1</div>
<div>2</div>
<div>3</div>
</body>
2.快速生成CSS样式语法
3.快速格式化代码
vscode新版本设置方法:
03-CSS的复合选择器
1.什么是复合选择器
2.后代选择器(重要)
<style>
/* 想把ol里面的li选择出来改为pink色 */
/* 后代选择器 元素2是元素1的后代 元素1和元素2之间用空格隔开 元素1是父级 元素2是子级 元素2可以是儿子 也可以是孙子 只要是元素1的后代即可 */
ol li {
color: pink;
}
ol li a {
text-decoration: none;
color: red;
}
.nav li a {
color: yellow;
}
</style>
</head>
<body>
<ol>
<li>我是ol的孩子</li>
<li>我是ol的孩子</li>
<li>我是ol的孩子</li>
<li><a href="#">我是ol的孙子</a></li>
</ol>
<ul>
<li>我是ul的孩子</li>
<li>我是ul的孩子</li>
<li>我是ul的孩子</li>
</ul>
<ul class="nav">
<li>我是ul的孩子</li>
<li>我是ul的孩子</li>
<li><a href="#">不会变化</a></li>
<li><a href="#">不会变化</a></li>
<li><a href="#">不会变化</a></li>
</ul>
</body>
3.子选择器(重要)
<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>复合选择器-子选择器</title>
<style>
.nav>a {
color: green;
text-decoration: none;
}
</style>
</head>
<body>
<div class="nav">
<a href="#">我是儿子</a>
<p>
<a href="#">我是孙子</a>
</p>
</div>
</body>
4.课堂练习
<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>课堂练习</title>
<style>
/* 将下面链接文字修改为红色 */
/* 使用后代选择器 */
.nav ul li a {
color: red;
}
/* 将下面的大肘子文字修改为红色 */
/* 使用子选择器 */
.hot>a {
color: red;
}
</style>
</head>
<body>
<div class="nav">
<ul>
<li><a href="#">百度</a></li>
<li><a href="#">百度</a></li>
</ul>
</div>
<div class="hot">
<a href="#">大肘子</a>
<ul>
<li><a href="#">猪头</a></li>
<li><a href="#">猪尾巴</a></li>
</ul>
</div>
</body>
5.并集选择器(重要)
<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>复合选择器-并集选择器</title>
<style>
/* 要求1: 请把熊大和熊二改成粉色 */
div,
p {
color: pink;
}
/* 要求2: 请把熊大和熊二改成粉色 还有 小猪一家改成粉色 */
div,
p,
.pig li {
color: pink;
}
</style>
</head>
<body>
<div>熊大</div>
<p>熊二</p>
<span>光头强</span>
<ul class="pig">
<li>小猪佩奇</li>
<li>猪爸爸</li>
<li>猪妈妈</li>
</ul>
</body>
6.伪类选择器
6.1链接伪类选择器
6.2 focus 伪类选择器
<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>
/* 把获得光标的input表单元素选取出来 */
input:focus {
background-color: pink;
color: red;
}
</style>
</head>
<body>
<input type="text">
<input type="text">
<input type="text">
</body>
7.复合选择器总结
04-CSS的元素显示模式
1.什么是元素显示模式
2.块元素
宽度不设置 会默认继承父级的宽度 如:div块级元素 的 父级元素是 body
body的宽度是浏览器的宽度
3.行内元素
4.行内块元素
5.元素显示模式总结
6.元素显示模式转换
<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>
a {
width: 100px;
height: 100px;
background-color: pink;
/* 把行内元素a 转换为 块级元素 */
display: block;
}
div {
width: 300px;
height: 200px;
background-color: green;
/* 把块级元素div 转换为 行内元素 */
display: inline;
}
span {
width: 200px;
height: 100px;
background-color: orange;
/* 把行内元素span 转换为 行内块元素 */
display: inline-block;
}
</style>
</head>
<body>
<a href="#">我是行内元素</a>
<a href="#">我是行内元素</a>
<div>我是块级元素</div>
<div>我是块级元素</div>
<span>行内元素转换为行内块元素</span>
<span>行内元素转换为行内块元素</span>
</body>
7.一个小工具snipaste的使用
8.课堂案例-简洁版小米侧边栏
<!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>
a {
width: 230px;
height: 40px;
background-color: #3f3d3d;
font-size: 14px;
line-height: 40px;
text-indent: 2em;
color: white;
text-decoration: none;
display: block;
}
a:hover {
background-color: #ff6700;
width: 230px;
}
</style>
</head>
<body>
<a href="#">
手机 电话卡
</a>
<a href="#">
电视 盒子
</a>
<a href="#">
电视 盒子
</a>
<a href="#">
出行 穿戴
</a>
<a href="#">
智能 路由器
</a>
<a href="#">
健康 儿童
</a>
<a href="#">
耳机 音响
</a>
</body>
</html>
9.单行文字垂直居中的原理
05-CSS的背景
1.背景颜色
2.背景图片
<style>
div {
width: 300px;
height: 300px;
/* 图片铺满了整个盒子 */
background-image: url(images/1.jpg);
}
</style>
</head>
<body>
<div></div>
</body>
3.背景平铺
<style>
div {
width: 1000px;
height: 500px;
background-color: black;
/* 图片铺满了整个盒子 */
background-image: url(images/2.jpg);
/* 默认情况下图片是平埔的*/
background-repeat: repeat;
/* 图片不平铺 */
background-repeat: no-repeat;
/* 图片在x轴上平铺 */
background-repeat: repeat-x;
/* 图片在y轴上平铺 */
background-repeat: repeat-y;
}
</style>
4.背景图片位置
<style>
div {
width: 1000px;
height: 1000px;
background-image: url(images/2.jpg);
background-color: black;
background-repeat: no-repeat;
/* 参数是方位名词 top center bottom left center right 两个值的与顺序无关*/
/* top; 和 top center;是等价的 x轴的值默认居中 */
background-position: top center;
}
</style>
图片方位参数 top center
5.背景位置案例一
<!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>
h3 {
width: 118px;
height: 40px;
font: 400 14px/40px 'Microsoft YaHei';
background-image: url(images/3.png);
background-repeat: no-repeat;
background-position: -30px 5px;
text-indent: 2em;
}
</style>
</head>
<body>
<h3>
成长守护平台
</h3>
</body>
</html>
生成效果:
6.背景位置案例二
<!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>
body {
background-image: url(images/4.png);
background-repeat: no-repeat;
background-position: center top;
}
</style>
</head>
<body>
</body>
</html>
生成效果:
7. 背景图像固定(背景附着)
8.背景属性复合写法
<style>
body {
/* background: 背景颜色 背景图片地址 背景平铺 背景图像滚动 背景位置 */
background: black url(images/4.png) no-repeat fixed top center;
}
</style>
9.背景颜色半透明
<!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>
div {
width: 300px;
height: 300px;
background: rgba(0, 0, 0, 0.3);
}
</style>
</head>
<body>
<div></div>
</body>
</html>
10.背景总结
06-综合案例
案例:五彩导航
<!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>
.nav a {
display: inline-block;
text-decoration: none;
font-size: 16px;
color: white;
background-color: pink;
width: 120px;
height: 58px;
text-align: center;
line-height: 58px;
}
.nav .orange {
background-image: url(images/orange.png);
background-repeat: no-repeat;
}
.nav .blue {
background-image: url(images/blue.png);
background-repeat: no-repeat;
}
.nav .purple {
background-image: url(images/purple.png);
background-repeat: no-repeat;
}
.nav .pink {
background-image: url(images/pink.png);
background-repeat: no-repeat;
}
.nav .orange:hover {
background-image: url(images/red.png);
}
.nav .blue:hover {
background-image: url(images/green.png);
}
.nav .purple:hover {
background-image: url(images/grey.png);
}
.nav .pink:hover {
background-image: url(images/yellow.png);
}
</style>
</head>
<body>
<div class="nav">
<a href="#" class="orange">五彩导航</a>
<a href="#" class="blue">五彩导航</a>
<a href="#" class="purple">五彩导航</a>
<a href="#" class="pink">五彩导航</a>
</div>
</body>
</html>
效果图:
鼠标悬停变颜色