HTML

标签

标题标签

1
2
3
4
5
6
7
<h1>标题标签</h1>
<h1>标题一共六级选,</h1>
<h2>文字加粗一行显。</h2>
<h3>由大到小依次减,</h3>
<h4>从重到轻随之变。</h4>
<h5>语法规范书写后,</h5>
<h6>具体效果刷新见。</h6>

段落标签

1
2
<p>在中国IT教育行业发展的轨迹中,
<br /> 能始终秉承着初心做教育的企业为数不多,而在李开复老师的心中,传智播客就是其中之一。在11年的风雨历程中,传智播客在中国IT教育行业留下了“为莘莘学子改变命运而讲课,为千万学生少走弯路而著书”的独特烙印。同时,传智播客也凭借着良好的口碑、更注重品质的教学及优秀的业绩增长成功吸引了众多知名投资者们的青睐,其中不乏创新工场、经纬、君度、蓝图、北城壹号等多个投资机构。</p>

文本格式标签

1
2
3
4
<strong>加粗</strong>	<b>加粗</b>
<em>倾斜</em> <i>倾斜</i>
<del>删除线</del> <s>删除线</s>
<ins>下划线</ins> <u>下划线</u>

div和span标签

1
2
3
4
5
6
   <div>我是一个div标签我一个人单独占一行</div>
<div>我是一个div标签我一个人单独占一行</div>
<span>百度</span>
<span>新浪</span>
<span>搜狐</span>
<span>块标签</span>

img标签

1
2
3
4
5
6
<img src="图片地址"
alt="图片出错时文字"
title="鼠标悬浮时的文字"
height="高度"
width="宽度"
border="图片描边大小"/>

超链接标签

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1.外部链接
<a href="http://www.qq.com" target="_blank"> 腾讯</a>
target 打开窗口的方式 默认的值是 _self 当前窗口打开页面 _blank 新窗口打开页面
<a href="http://www.itcast.cn" target="_blank">传智播客</a>

2.内部链接: 网站内部页面之间的相互链接
<a href="gongsijianjie.html" target="_blank">公司简介</a>

3.空链接:#
<a href="#">公司地址</a>

4.下载链接: 地址链接的是 文件 .exe 或者是 zip 等压缩包形式
<a href="img.zip">下载文件</a>

5.网页元素的链接
<a href="http://www.baidu.com"><img src="img.jpg"/></a>

6. 锚点定位,点击之后跳转到对应id的元素
<a href="#live">个人生活</a><br />
***
***
***
<h3 id="live">个人生活</h3>

表格标签

HTML表格(table)元素有许多属性,以下是一些常见的属性:

  1. border:控制表格边框是否显示。默认值为 “1”。
  2. cellpadding:控制单元格内文本的间距。默认值为 “0”。
  3. cellspacing:控制单元格之间的间距。默认值为 “0”。
  4. width:控制表格的宽度。默认值为 “100%”。
  5. height:控制表格的高度。默认值为 “100%”。
  6. bgcolor:控制表格的背景颜色。
  7. align:控制表格在页面中的对齐方式。
  8. valign:控制表格中单元格在垂直方向上的对齐方式。
  9. bordercolor:控制表格边框的颜色。
  10. rules:控制表格边框的显示方式。可选值有 “none”(不显示边框)、“groups”(显示分隔线)、“rows”(显示行边框)和 “cols”(显示列边框)。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<table>
<thead>表头部分
<tr>
<th>姓名</th>表头单元格
<th>年龄</th>
<th>职业</th>
</tr>
</thead>
<tbody>表格主体
<tr>
<td>张三</td>表格单元格
<td>25</td>
<td>程序员</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
<td>设计师</td>
</tr>
<tr>
<td>王五</td>
<td>28</td>
<td>销售</td>
</tr>
</tbody>
</table>

合并单元格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<table width="500" height="249" border="1" cellspacing="0">
<tr>
<td></td>
<td colspan="2"></td>

</tr>
<tr>
<td rowspan="2"></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>

列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<ul>无序列表
<li>榴莲</li>
<li>臭豆腐</li>
<li>鲱鱼罐头</li>
<li>
<p>123</p>
</li>
</ul>

<ol>有序列表
<li>刘德华 10000</li>
<li>刘若英 1000</li>
<li>pink老师 1</li>
</ol>

<dl>自定义列表,无修饰
<dt>关注我们</dt>
<dd>新浪微博</dd>
<dd>官方微信</dd>
<dd>联系我们</dd>
<dt>关注我们</dt>
<dd>新浪微博</dd>
<dd>官方微信</dd>
<dd>联系我们</dd>
</dl>

表单

表单域

1
2
3
  <form action="demo.php提交地址" method="POST提交方式" name="表单名字">
各种控件
</form>

表单元素

预览表单元素

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<form action="xxx.php" method="get">

<!-- text 文本框 用户可以里面输入任何文字 -->
用户名: <input type="text" name="username" value="张三" maxlength="6" placeholder="请输入名字"> <br>

<!-- password 密码框 用户看不见输入的密码 -->
密码: <input type="password" name="pwd" > <br>

<!-- radio 单选按钮 可以实现多选一 -->
<!-- name 是表单元素名字 这里性别单选按钮必须有相同的名字name 才可以实现多选1 -->
<!-- 单选按钮和复选框可以设置checked 属性, 当页面打开的时候就可以默认选中这个按钮 -->
性别: 男 <input type="radio" name="sex" value="男">
<input type="radio" name="sex" value="女" checked="checked">
人妖 <input type="radio" name="sex" value="人妖"> <br>

<!-- checkbox 复选框 可以实现多选 -->
爱好: 吃饭 <input type="checkbox" name="hobby" value="吃饭">
睡觉 <input type="checkbox" name="hobby">
打豆豆 <input type="checkbox" name="hobby" checked="checked"> <br>

<!-- 点击了提交按钮,可以把 表单域 form 里面的表单元素 里面的值 提交给后台服务器 -->
<input type="submit" value="免费注册">

<!-- 重置按钮可以还原表单元素初始的默认状态 -->
<input type="reset" value="重新填写">

<!-- 普通按钮 button 后期结合js 搭配使用-->
<input type="button" value="获取短信验证码"> <br>

<!-- 文件域 使用场景 上传文件使用的 -->
上传头像: <input type="file" >
</form>

label标签

1
2
3
4
5
6
增加用户选中点面积,更加便于点击
label标签通过for和表单元素id进行绑定

<label for="text"> 用户名:</label> <input type="text" id="text" >
<input type="radio" id="nan" name="sex"> <label for="nan"></label>
<input type="radio" id="nv" name="sex"> <label for="nv"></label>

select标签

1
2
3
4
5
6
<select>
<option>山东</option>
<option>北京</option>
<option>天津</option>
<option selected="selected">火星</option>
</select>

文本域标签

1
<textarea cols="50" rows="5">pink老师,我知道这个反馈留言是textarea来做的 </textarea>

H5标签

语义化标签

  • <header> 头部标签
  • <nav> 导航标签
  • <article> 内容标签
  • <section> 定义文档某个区域
  • <aside> 侧边栏标签
  • <footer> 尾部标签

音视频标签

1
2
<audio src="media/music.mp3" autoplay="autoplay" controls="controls"></audio>
<video src="media/mi.mp4" autoplay="autoplay" muted="muted" loop="loop" poster="media/mi9.jpg"></video>

input表单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    <form action="">
<ul>
<li>邮箱: <input type="email" /></li>
<li>网址: <input type="url" /></li>
<li>日期: <input type="date" /></li>
<li>时间: <input type="time" /></li>
<li>数量: <input type="number" /></li>
<li>手机号码: <input type="tel" /></li>
<li>搜索: <input type="search" /></li>
<li>颜色: <input type="color" /></li>
<!-- 当我们点击提交按钮就可以验证表单了 -->
<li> <input type="submit" value="提交"></li>
</ul>
</form>

/*****************************************************************/

<form action="">
<input type="search" name="sear" id="" required="required" placeholder="pink老师" autofocus="autofocus" autocomplete="off">
<input type="file" name="" id="" multiple="multiple">
<input type="submit" value="提交">
</form>

Emmet语法

快速撸HTML

CSS

选择器

类名选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
格式为.类名
一个标签可以有多个类名,用空格隔开
<style>
.box {
width: 150px;
height: 100px;
font-size: 30px;
}
.red {

/* 背景颜色 */
background-color: red;
}
.green {

background-color: green;
}
</style>
<body>
<div class="box red">红色</div>
<div class="box green">绿色</div>
<div class="box red">红色</div>
</body>

id选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
格式为#id
<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">
<title>基础选择器之id选择器</title>
<style>
/* id选择器的口诀: 样式#定义, 结构id调用, 只能调用一次, 别人切勿使用 */
#pink {
color: pink;
}

</style>
</head>
<body>
<div id="pink">迈克尔·杰克逊</div>
<div>pink老师</div>
</body>
</html>

通配符选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE 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">
<title>基础选择器之通配符选择器</title>
<style>
* {
color: red;
}
/* * 这里把 html body div span li 等等的标签都改为了红色 */
</style>
</head>
<body>
<div>我的</div>
<span>我的</span>
<ul>
<li>还是我的</li>
</ul>
</body>
</html>

后代选择器和子元素选择器

1
2
3
4
5
后代选择器
格式p a
子元素选择器 p > a

子元素选择器只能选择直接子元素,后代选择器可以选择所有子元素。

并集选择器

1
2
3
4
5
6
7
一般竖着写并集选择器
div,
p,
.pig li {
color: pink;
}

伪类选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
     /* 1.未访问的链接 a:link  把没有点击过的(访问过的)链接选出来 */
a:link {
color: #333;
text-decoration: none;
}

/*2. a:visited 选择点击过的(访问过的)链接 */
a:visited {
color: orange;
}

/*3. a:hover 选择鼠标经过的那个链接 */
a:hover {
color: skyblue;
}

/* 4. a:active 选择的是我们鼠标正在按下还没有弹起鼠标的那个链接 */
a:active {
color: green;
}

/* // 把获得光标的input表单元素选取出来 */
input:focus {
background-color: pink;
color: red;
}

属性选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE 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">
<title>CSS3新增属性选择器</title>
<style>
/* 必须是input 但是同时具有 value这个属性 选择这个元素 [] */
/* input[value] {
color:pink;
} */
/* 只选择 type =text 文本框的input 选取出来 */
input[type=text] {
color: pink;
}
/* 选择首先是div 然后 具有class属性 并且属性值 必须是 icon开头的这些元素 */
div[class^=icon] {
color: red;
}
section[class$=data] {
color: blue;
}
div.icon1 {
color: skyblue;
}
/* 类选择器和属性选择器 伪类选择器 权重都是 10 */
</style>
</head>
<body>
<!-- 1. 利用属性选择器就可以不用借助于类或者id选择器 -->
<!-- <input type="text" value="请输入用户名">
<input type="text"> -->
<!-- 2. 属性选择器还可以选择属性=值的某些元素 重点务必掌握的 -->
<input type="text" name="" id="">
<input type="password" name="" id="">
<!-- 3. 属性选择器可以选择属性值开头的某些元素 -->
<div class="icon1">小图标1</div>
<div class="icon2">小图标2</div>
<div class="icon3">小图标3</div>
<div class="icon4">小图标4</div>
<div>我是打酱油的</div>
<!-- 4. 属性选择器可以选择属性值结尾的某些元素 -->
<section class="icon1-data">我是安其拉</section>
<section class="icon2-data">我是哥斯拉</section>
<section class="icon3-ico">哪我是谁</section>

</body>
</html>

结构伪类选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
        /* 1. 选择ul里面的第一个孩子 小li */
ul li:first-child {
background-color: pink;
}
/* 2. 选择ul里面的最后一个孩子 小li */
ul li:last-child {
background-color: pink;
}
/* 3. 选择ul里面的第2个孩子 小li */
ul li:nth-child(2) {
background-color: skyblue;
}
ul li:nth-child(6) {
background-color: skyblue;
}

/*************************************************************/

/* 1.把所有的偶数 even的孩子选出来 */
ul li:nth-child(even) {
background-color: #ccc;
}

/* 2.把所有的奇数 odd的孩子选出来 */
ul li:nth-child(odd) {
background-color: gray;
}
/* 3.nth-child(n) 从0开始 每次加1 往后面计算 这里面必须是n 不能是其他的字母 选择了所有的孩子*/
/* ol li:nth-child(n+3) {
background-color: pink;
} */
ol li:nth-child(-n+3) {
background-color: pink;
}

/*************************************************************/
ul li:first-of-type {
background-color: pink;
}

  • E:nth-child(n) 匹配父元素的第n个子元素E,也就是说,nth-child 对父元素里面所有孩子排序选择(序号是固定的) 先找到第n个孩子,然后看看是否和E匹配
  • E:nth-of-type(n) 匹配同类型中的第n个同级兄弟元素E,也就是说,对父元素里面指定子元素进行排序选择。 先去匹配E ,然后再根据E 找第n个孩子

伪元素选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE 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">
<title>伪元素选择器before和after</title>
<style>
/*一般用于简单加个图标,属于行内元素,且无法找到*/
div {
width: 200px;
height: 200px;
background-color: pink;
}
/* div::before 权重是2 */
div::before {
/* 这个content是必须要写的 */
/* display: inline-block; */
content: '我';
/* width: 30px;
height: 40px;
background-color: purple; */
}
div::after {
content: '小猪佩奇';
}
</style>
</head>
<body>
<div>

</div>
</body>
</html>

CSS的特点

  1. 层叠性:子级元素会覆盖父级元素
  2. 继承性:子级元素会继承父级
  3. 优先级:
选择器 权重
继承/* 0 0 0 0
元素选择器 0 0 0 1
(伪)类选择器 0 0 1 0
ID选择器 0 1 0 0
内联样式 1 0 0 0
!importrant 无穷
  1. 权重计算:四组数字,不会进位

元素显示分类

块元素

常见的块元素

1
<h1>~<h6>、<p>、<div>、<ul>、<ol>、<li>

标签是最典型的块元素。

块级元素的特点

  • 比较霸道,自己独占一行。
  • 高度,宽度、外边距以及内边距都可以控制。
  • 宽度默认是容器(父级宽度)的100%。
  • 是一个容器及盒子,里面可以放行内或者块级元素。

注意:

文字类的元素内不能放块级元素

1
2
<p> 标签主要用于存放文字,因此 <p> 里面不能放块级元素,特别是不能放<div> 
同理, <h1>~<h6>等都是文字类块级标签,里面也不能放其他块级元素

行内元素

常见的行内元素:

1
<a>、<strong>、<b>、<em>、<i>、<del>、<s>、<ins>、<u>、<span>

标签是最典型的行内元素。有的地方也将行内元素称为内联元素。

行内元素的特点:

  • 相邻行内元素在一行上,一行可以显示多个。
  • 高、宽直接设置是无效的。
  • 默认宽度就是它本身内容的宽度。
  • 行内元素只能容纳文本或其他行内元素。

注意: 链接里面不能再放链接 特殊情况链接 里面可以放块级元素,但是给 转换一下块级模式最安全

行内块元素

常见的行内块标签

1
<img />、<input />、<td> 

它们同时具有块元素和行内元素的特点。有些资料称它们为行内块元素。

行内块元素的特点

  • 和相邻行内元素(行内块)在一行上,但是他们之间会有空白缝隙。
  • 一行可以显示多个(行内元素特点)。默认宽度就是它本身内容的宽度(行内元素特点)。
  • 高度,行高、外边距以及内边距都可以控制(块级元素特点)。

显示模式转换

1
2
3
4
转换为块元素:display:block;
转换为行内元素:display:inline;
转换为行内块:display: inline-block;
不显示:display: none;

盒模型

盒模型

border

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
div {
width: 300px;
height: 200px;
/* border-width 边框的粗细 一般情况下都用 px */
border-width: 5px;
/* border-style 边框的样式 solid 实线边框 dashed 虚线边框 dotted 点线边框*/
border-style: solid;
/* border-style: dashed; */
/* border-style: dotted; */
/* border-color 边框的颜色 */
border-color: pink;

/* 复合写法 */
border-top: 5px solid pink;

/*圆角*/
border-radius: 10px;
border-top-left-radius: 20px;
}

border会占据盒子的大小

padding

1
2
3
4
5
6
7
8
9
10
div {
width: 200px;
height: 200px;
background-color: pink;
padding-left: 20px;
padding-top: 30px;
/*顺时针旋转,哪里省略补充对边*/
padding: 5px 10px 20px 30px;
}

padding会撑大盒子,但当元素没有设定宽高时,padding会占据盒子大小

margin

1
2
3
4
5
6
7
.header {
/*一般用于对齐*/
width: 900px;
height: 200px;
background-color: pink;
margin: 100px auto;
}

相邻和嵌套块元素会合并外边距

阴影

1
2
box-shadow: 10px 10px 10px -4px rgba(0, 0, 0, .3);
text-shadow: 5px 5px 6px rgba(0, 0, 0, .3);

css3盒模型

1
2
3
4
5
6
/* 这样盒模型就变成了content + padding + border = with / height */     
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

Position定位

relative

  • 它是相对于自己原来的位置来移动的(移动位置的时候参照点是自己原来的位置)。
  • 相对定位并没有脱标,也就是原来所在的位置会被保留。一般用来作为绝对定位的父级元素

absolute

  • 脱标,不占据位置
  • 父级无定位以document为定位,有则以父级定位

fixed

固定不动,一直显示在屏幕上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE 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">
<title>固定定位小技巧-固定到版心右侧</title>
<style>
.w {
width: 800px;
height: 1400px;
background-color: pink;
margin: 0 auto;
}
.fixed {
position: fixed;
/* 1. 走浏览器宽度的一半 */
left: 50%;
/* 2. 利用margin 走版心盒子宽度的一半距离 */
margin-left: 405px;
width: 50px;
height: 150px;
background-color: skyblue;
}
</style>
</head>
<body>
<div class="fixed"></div>
<div class="w">版心盒子 800像素</div>

</body>
</html>

sticky

粘性定位在滚动后会锁在最上层

z-index

1
2
z-index: 1;
/*值越大越靠前*/

利用绝对定位居中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE 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">
<title>绝对定位水平垂直居中</title>
<style>
.box {
position: absolute;
/* 1. left 走 50% 父容器宽度的一半 */
left: 50%;
/* 2. margin 负值 往左边走 自己盒子宽度的一半 */
margin-left: -100px;
top: 50%;
margin-top: -100px;
width: 200px;
height: 200px;
background-color: pink;
/* margin: auto; */
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>

属性

字体属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
p{
font-family: 'Times New Roman', Times, serif;
font-size: 16px;
font-weight: 400;
font-style: italic;
font: font-style font-weight font-size/line-height font-family;

color: rgb(255, 0, 255);
text-align: right;
text-decoration: line-through/overline/underline;
text-indent: 2em;//文字首行缩进
line-height: 25px;//多用于文字中心对齐

}

背景属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
div {
width: 200px;
height: 200px;

background-color: pink;

background-image: url(images/logo.png);

/*默认为平铺*/
background-repeat: repeat-y/no-repeat/repeat-x;

/* 背景对齐方式
background-position: 方位名词或者10px;
y轴默认为center*/
background-position: right top;

/*固定背景图层*/
background-attachment: fixed;

/*复合写法*/
background: black url(images/bg.jpg) no-repeat fixed center top;

/*渐变背景*/
background: -webkit-linear-gradient(top left, red, blue);
}

显示隐藏

1
2
3
4
5
6
7
/*直接隐藏不渲染*/
display: none;
/*渲染但不显示*/
visibility: hidden;

/*处理超出内容的部分*/
overflow: hidden

图片滤镜

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*对图片进行简单处理,实际上其实可以对其和子元素做处理,而不只是图像*/
html{
/*画面全灰白*/
filter: grayscale(100%);
}
filter: blur(5px);
filter: brightness(0.4);
filter: contrast(200%);
filter: drop-shadow(16px 16px 20px blue);
filter: grayscale(50%);
filter: hue-rotate(90deg);
filter: invert(75%);
filter: opacity(25%);
filter: saturate(30%);
filter: sepia(60%);

宽度处理函数

1
width: calc(100% - 30px);

过度效果

1
2
/*应用属性 持续时间 贝塞尔曲线*/
transition: all 0.5s ease-out;

At-rules

@property

1

布局

Flex布局

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*flex布局由主轴和交叉轴为框架,其中交叉轴垂直于主轴,默认情况下,主轴为水平方向,起始方向为左边*/
div {
display: flex;
width: 800px;
height: 300px;
background-color: pink;

/* 默认的主轴是 x 轴 row ,翻转起始线则row-reverse*/
flex-direction: row;

/* justify-content: 是设置主轴上子元素的排列方式 */
/* justify-content: flex-start; */
/* justify-content: flex-end; */

/* 让我们子元素居中对齐 */
/* justify-content: center; */

/* 平分剩余空间 */
/* justify-content: space-around; */

/* 先两边贴边, 在分配剩余的空间 */
justify-content: space-between;

/* flex布局中,默认的子元素是不换行的, 如果装不开,会缩小子元素的宽度,放到父元素里面 */
/* flex-wrap: nowrap; */
flex-wrap: wrap;

/*交叉轴居中对齐*/
align-items: center;

/* 当出现多行时,即flex-wrap: wrap;时,对齐方式要用align-center:控制 */
align-content: space-around;
}
div span{
/*flex为复合属性有下面三个属性共同控制*/
flex:flex-grow flex-shrink flex-basis

/*flex-grow为子元素需要伸长时分配剩余空间所占大小,多个子元素设置不同的flex-grow会依照比例分配*/
/*flex-shrink决定了子元素需要收缩时分配剩余空间所占大小*/
/*flex-basis为子元素的初始预定大小*/

/*felx简写*/
/*flex:initial相当于将属性设置为"flex: 0 1 auto"。*/
/*flex:auto相当于flex: 1 1 auto*/

/*align-self会覆盖当前子元素的align-items值,从而让特点的子元素使用其他的对齐方式*/
align-self:flex-end
}

Javascript

DOM 文档对象模型

DOM树

整个HTML文档其实是由一个个DOM节点构成,也是DOM对象,它们共同构成了DOM树

DOM树

获取DOM对象

1
2
3
const box = document.querySelector('div') //只匹配第一个div,其中''内的内容和选择器写法一致
const boxs = document.querySelectorAll('div')//获取所有div,并返回一个伪数组
const ele = document.getElementById('elementId')//通过id获取

操作DOM对象

修改内容

1
2
3
const intro = document.querySelector('.intro')
intro.innerText = '嗨~ 我叫李雷!' //只修改内容,不解析标签
intro.innerHTML = '<h4>嗨~ 我叫韩梅梅!</h4>' //会解析标签

修改常见属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//之前HTML中学到的标签属性都能进行修改

const pic = document.querySelector('.pic')
pic.src = './images/lion.webp' //修改图片路径

const box = document.querySelector('.intro')
box.style.color = 'red' //修改样式

box.style.backgroundColor = 'pink'
/*******************************************
********************************************
注意!!!
由于js对象中不能含有-符号,遇到含有-符号的样式需要去掉并将后面的首字母改成大写
********************************************
********************************************/

操作类名

1
2
3
4
5
6
7
8
//通过对类名的修改,可以实现对用户操作的反馈

const box = document.querySelector('.intro')
box.className = 'pink' //将类名重命名

box.classList.add('active') //增加类
box.classList.remove('active') //移除类
box.classList.toggle('one')//切换类 即有则删去,无则添加

修改表单属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// 表单的各种属性(type,value)也可以修改

//输入框
let input = document.querySelector('input')
input.value = '小米手机'
input.type = 'password'

//按钮
let btn = document.querySelector('button')
btn.disabled = false

//复选框
let checkbox = document.querySelector('.agree')
checkbox.checked = false

自定义属性

在html5中推出来了专门的data-自定义属性,在标签上一律以data-开头,在DOM对象上一律以dataset对象方式获取

1
2
3
4
// 1. 获取元素
let div = document.querySelector('div')
// 2. 获取自定义属性值
console.log(div.dataset.id)

定时器

事件

Array方法

Array.find 返回符合条件的第一个对象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
   // 遍历数组,返回符合条件的第一个对象
const arr = [
{
name: '小米',
price: 1999
},
{
name: '华为',
price: 3999
},
]
const mi = arr.find(item => item.name === '小米')
console.log(mi)
>> {
"name": "小米",
"price": 1999
}

Array.from 将伪数组转换为真数组

1
2
3
4
5
6
7
//  Array.from(lis) 把伪数组转换为真数组
const lis = document.querySelectorAll('ul li')
// console.log(lis)
// lis.pop() 报错
const liss = Array.from(lis)
liss.pop()
console.log(liss)

String方法

String.split 将字符串转化为数组

1
2
3
4
5
const str = 'The quick brown fox jumps over the lazy dog.';

const words = str.split(' ');
console.log(words[3]);
// Expected output: "fox"

String.substring 截取字符串

1
2
3
4
5
6
7
8
const str = 'Mozilla';

console.log(str.substring(1, 3));
// Expected output: "oz" 前闭后开

console.log(str.substring(2));
// Expected output: "zilla"

String.startsWith 判断是否以某字符开头

1
2
3
4
5
6
7
const str1 = 'Saturday night plans';

console.log(str1.startsWith('Sat'));
// Expected output: true

console.log(str1.startsWith('Sat', 3));
// Expected output: false 从第四个字符串开始查找

String.includes 判断字符串是否包含指定内容

1
2
3
4
5
6
7
8
const str = "To be, or not to be, that is the question.";

console.log(str.includes("To be")); // true
console.log(str.includes("question")); // true
console.log(str.includes("nonexistent")); // false
console.log(str.includes("To be", 1)); // false
console.log(str.includes("TO BE")); // false
console.log(str.includes(""));// true