一、HTML
1.什么是 HTML?
- HTML 指的是超文本标记语言: HyperText Markup Language(面试被问住啦啊啊啊)
- HTML 不是一种编程语言,而是一种标记语言
- 标记语言是一套标记标签 (markup tag)
- HTML 使用标记标签来描述网页
- HTML 文档包含了HTML 标签及文本内容
- HTML文档也叫做 web 页面
2.HTML的结构
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<h1>我的第一个标题</h1>
<p>我的第一个段落。</p>
</body>
</html>
- <!DOCTYPE html> 声明为 HTML5 文档
- <html> 元素是 HTML 页面的根元素
- <head> 元素包含了文档的元(meta)数据
- <title> 元素描述了文档的标题
- <body> 元素包含了可见的页面内容
- <h1> 元素定义一个大标题(h1-h6)
- <p> 元素定义一个段落
3.HTML常用标签
1)HTML 标题(Heading)是通过<h1> - <h6> 标签来定义的。使用<h1>-<h6>字体会自动加粗。
2)HTML 段落是通过标签 <p> 来定义的。
3)HTML 链接是通过标签 <a> 来定义的。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<a href="index.html">链接</a>
</body>
</html>
<a>标签的进阶用法
1)
<a href="https://www.example.com">
<img src="example.jpg" alt="示例图片">
</a>
让图片当超链接
<a href="#section2">跳转到第二部分</a>
<!-- 在页面中的某个位置 -->
<a name="section2"></a>
跳转
2)
- 下载文档
<a href="document.pdf" download>下载文档</a>
- 在新窗口打开文档
<a href="https://www.runoob.com/" target="_blank" rel="noopener noreferrer"> 访问菜鸟教程!</a>
- 跳出框架
<a href="http://www.runoob.com/" target="_top">点击这里!</a>
- 简单版电子邮件链接
<a href="mailto:someone@example.com?Subject=Hello%20again" target="_top">发送邮件</a>
- 复杂版发送电子邮件
<a href="mailto:someone@example.com?cc=someoneelse@example.com&bcc=andsomeoneelse@example.com&subject=Summer%20Party&body=You%20are%20invited%20to%20a%20big%20summer%20party!" target="_top">发送邮件!</a>
- 没有下划线的链接
<a href="http://www.runoob.com/" style="text-decoration:none;">访问 runoob.com!</a>
<img src=””width=””height=””border=””alt=”> 图片 注:alt中内容将在图片无显示的时候代替图片内容
4)HTML 图像是通过标签 <img> 来定义的
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<a href="index.html">链接</a>
<img src="images/logo.png">
</body>
</html>
5)HTML中<br> / <br/>标签是换行符
6)<hr> 标签在 HTML 页面中创建水平线。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<a href="index.html">链接</a>
<hr>
<p>aaaaa</p>
</body>
</html>
7)<!-- -->注释文本
8)<em></em>定义强调文本(斜体),<em>替换<i> (<i>斜体字</i>)
9) <big></big>大号文本
10) <sub>下标</sub> <sup>上标</sup>
11) <del>定义删除字</del>
12)<ins>定义插入字</ins>
13)<link> 标签定义了文档与外部资源之间的关系
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
14)<style> 标签定义了HTML文档的样式文件引用地址
<head>
<style type="text/css">
body {
background-color:yellow;
}
p {
color:blue
}
</style>
</head>
15)
HTML 表格由 <table> 标签来定义。
HTML 表格是一种用于展示结构化数据的标记语言元素。
每个表格均有若干行(由 <tr> 标签定义),每行被分割为若干单元格(由 <td> 标签定义),表格可以包含标题行(<th>)用于定义列的标题。
- tr:tr 是 table row 的缩写,表示表格的一行。
- td:td 是 table data 的缩写,表示表格的数据单元格。
- th:th 是 table header的缩写,表示表格的表头单元格、】
- <thead > 用于定义表格的标题部分: 在 <thead > 中,使用 <th > 元素定义列的标题,以上实例中列标题分别为"列标题1","列标题2"和"列标题3"。
- <tbody > 用于定义表格的主体部分: 在 <tbody > 中,使用 <tr > 元素定义行,并在每行中使用 <td > 元素定义单元格数据,以上实例中有两行数据,每行包含三个单元格。
- <tfoot > 可用于在表格的底部定义摘要、统计信息等内容。 <caption > 可用于为整个表格定义标题。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>造梦西游</title>
<style>
h1{
text-align:center;
color:lightskyblue;
}
h2{
text-shadow:2px 2px darkturquoise;
text-align:center;
}
th{
background-color:aqua;
}
a:link{color:red;}
a:visited{color:blue;}
a:hover{color:green;font-size:150%;}
a:active{color:pink;}
a{text-decoration: none;}
.one{outline:green solid;}
.two{outline:red dotted;}
</style>
</head>
<body>
<h1>造梦西游三大闹天庭篇宣花锤</h1>
<hr style="width:730px;border-top:1px dashed #0066CC;"/>
<table align="center" border="2" cellpadding="30" style="text-align:left" cellspacing="0">
<tr><th colspan="2">装备名称</th><th>装备类型</th><th>生命值</th><th>魔法值</th></tr>
<tr><td colspan="2">宣花锤</td><td>武器</td><td>100~170</td><td>/</td></tr>
<tr><td rowspan="5" colspan="2"><img src="images/xuanhuachui.png" alt="宣花锤"></td><th>品质</th><th>攻击力</th><th>防御力</th></tr>
<tr><td>优秀</td><td>20~26</td><td>/</td></tr>
<tr><th>暴击力</th><th>闪避</th><th>其他属性</th></tr>
<tr><td>/</td><td>/</td><td>/</td></tr>
<tr><th>装备描述</th><td colspan="3">街喧闹,人过往,且记曾相识,不为少年留。</td></tr>
<tr><th>获取方式</th><td colspan="4">打败巨灵神有几率掉落(巨灵神小档案:<a href="https://news.4399.com/gonglue/zmxy3/boss/132055.html">大闹天庭篇巨灵神</a>)</td></tr>
</table>
<br>
<table align="center">
<caption><h2>造梦问答</h2></caption>
<td>
<ul>
<li><span style="cursor:help"><a href="https://news.4399.com/gonglue/zmxy3/wenda/335435.html">大闹天庭篇的圣诞老人掉落什么</a></span></li>
<li><a href="https://news.4399.com/gonglue/zmxy3/wenda/335433.html" >大闹天庭篇后羿助战在哪</a></li>
<li><a href="https://news.4399.com/gonglue/zmxy3/wenda/332694.html">大闹天庭篇凶兽碎片怎么获得</a></li>
<li><a href="https://news.4399.com/gonglue/zmxy3/wenda/332690.html">大闹天庭篇花宴怎么合成</a></li>
<li><a href="https://news.4399.com/gonglue/zmxy3/wenda/332688.html">大闹天庭篇怎么开启等级上限</a></li>
</ul>
</td>
</table>
<table align="center">
<caption><h2>猜你想找</h2></caption>
<td>
<ol>
<li><a href="https://news.4399.com/gonglue/zmxy3/wenda/335435.html">大闹天庭篇唐僧技能搭配</a></li>
<li><a href="https://news.4399.com/gonglue/zmxy3/wenda/335433.html">大闹天庭篇孙悟空技能搭配</a></li>
<li><a href="https://news.4399.com/gonglue/zmxy3/wenda/332694.html">大闹天庭篇猪八戒技能搭配</a></li>
<li><a href="https://news.4399.com/gonglue/zmxy3/wenda/332690.html">大闹天庭篇沙僧技能搭配</a></li>
</ol>
</td>
</table>
<table align="center">
<caption><h2>玩家看法</h2></caption>
<tr><td>
<form action="">
户名:<input type="text" name="用户名"><br>
密码:<input type="password" name="密码"><br>
</form>
</td><td> </td><td><input type="submit" value="登录"></td></tr>
<tr><td> <form action=""><p>性别:<input type="radio" name="sex" value="男">男 <input type="radio" name="sex" value="女">女</p></form></td></tr>
<tr><td><form action=""><p>你最喜欢的角色:</p><input type="radio" name="角色" value="唐僧">唐僧<br>
<input type="radio" name="角色" value="孙悟空" checked>孙悟空<br>
<input type="radio" name="角色" value="猪八戒">猪八戒<br>
<input type="radio" name="角色" value="沙僧">沙僧<br>
</form></td></tr>
<tr><td><form action=""><p>你最喜欢的地图:</p>
<input type="checkbox" name="地图" value="碧游宫" > 碧游宫<br>
<input type="checkbox" name="地图" value="截教天境"> 截教天境<br>
<input type="checkbox" name="地图" value="天庭">天庭 <br>
</form></td></tr>
</table>
<div style="text-align:center">
<textarea rows="10" cols="60" >
点击输入你的评论,跟小编说说你的看法!
</textarea>
<form aciton="">
<input type="submit" value="我要发表" >
</form>
</div>
</body>
</html>
16)
<ul>
<li><li/>
<ul/>
无序列表
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
</ul>
</body>
</html>
17)
<ol>
<li><li/>
<ol/>
有序列表
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<ol>
<li>1</li>
<li>2</li>
</ol>
</body>
</html>
18)区块元素
1.<div>定义了文档的区域,块级 (block-level)
2.<span>用来组合文档中的行内元素, 内联元素(inline)
19)表单元素
<form>
元素用于创建表单,action
属性定义了表单数据提交的目标 URL,method
属性定义了提交数据的 HTTP 方法(这里使用的是 "post")。<label>
元素用于为表单元素添加标签,提高可访问性。<input>
元素是最常用的表单元素之一,它可以创建文本输入框、密码框、单选按钮、复选框等。type
属性定义了输入框的类型,id
属性用于关联<label>
元素,name
属性用于标识表单字段。<select>
元素用于创建下拉列表,而<option>
元素用于定义下拉列表中的选项。
1.
- 1
普通输入框和密码输入框.<form action=""> Username: <input type="text" name="user"><br> Password: <input type="password" name="password"> </form>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="">
Username: <input type="text" name="user"><br>
Password: <input type="password" name="password">
</form>
</body>
</html>
2.
<form action="">
<input type="radio" name="sex" value="male">男<br>
<input type="radio" name="sex" value="female">女
</form>
单选
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="">
<input type="radio" name="sex" value="male">男<br>
<input type="radio" name="sex" value="female">女
</form>
</body>
</html>
3.
<form>
<input type="checkbox" name="vehicle" value="Bike">我喜欢自行车<br>
<input type="checkbox" name="vehicle" value="Car">我喜欢小汽车
</form>
复选
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form>
<input type="checkbox" name="vehicle" value="Bike">我喜欢自行车<br>
<input type="checkbox" name="vehicle" value="Car">我喜欢小汽车
</form>
</body>
</html>
4.
<form name="input" action="html_form_action.php" method="get">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
提交
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form name="input" action="html_form_action.php" method="get">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>
</body>
</html>
5.
<form action="">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat" selected>Fiat</option>
<option value="audi">Audi</option>
预选下拉菜单
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat" selected>Fiat</option>
<option value="audi">Audi</option>
</body>
</html>
4.HTML的属性
1)<a href="http://www.runoob.com">这是一个链接</a> 连接的地址在href属性中定义
2)class 为html元素定义一个或多个类名(classname)
3)id 定义元素的唯一id
4)style 规定元素的行内样式(inline style)
5)title 描述了元素的额外信息 (作为工具条使用)
二、CSS
1.什么是 CSS?
- CSS 指层叠样式表 (Cascading Style Sheets)
- 样式定义如何显示 HTML 元素
- 样式通常存储在样式表中
- 把样式添加到 HTML 4.0 中,是为了解决内容与表现分离的问题
- 外部样式表可以极大提高工作效率
- 外部样式表通常存储在 CSS 文件中
- 多个样式定义可层叠为一个
2.CSS语法
p
{
color:red;
text-align:center;
}
注:CSS声明总是以分号 ; 结束,声明总以大括号 {} 括起来;CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明;
该例中p为选择器,color与text-align均为属性,red与center均为值。
3.CSS 注释
注释是用来解释你的代码,并且可以随意编辑它,浏览器会忽略它。
CSS注释以 /* 开始, 以 */ 结束, 如:
/*这是个注释*/
p
{
text-align:center;
/*这是另一个注释*/
color:black;
font-family:arial;
}
4.CSS选择器
1)id选择器
id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式。
HTML元素以id属性来设置id选择器,CSS 中 id 选择器以 "#" 来定义。
以下的样式规则应用于元素属性 id="one"
#one
{
text-align:center;
color:red;
}
注: ID属性不要以数字开头,数字开头的ID在 Mozilla/Firefox 浏览器中不起作用。
2)class选择器
class 选择器用于描述一组元素的样式,class 选择器有别于id选择器,class可以在多个元素中使用。
class 选择器在 HTML 中以 class 属性表示, 在 CSS 中,类选择器以一个点 . 号显示:
在以下的例子中,所有拥有 center 类的 HTML 元素均为居中
.one
{
text-align:center;
color:red;
}
5.CSS的创建(样式表)
1)外部样式表(External style sheet)
当样式需要应用于很多页面时,外部样式表将是理想的选择。在使用外部样式表的情况下,你可以通过改变一个文件来改变整个站点的外观。每个页面使用 <link> 标签链接到样式表。 <link> 标签在(文档的)头部,样式表应该以 .css 扩展名进行保存
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head
>
注:不要在属性值与单位之间留有空格(如:"margin-left: 20 px" ),正确的写法是 "margin-left: 20px" 。
2)内部样式表(Internal style sheet)
当单个文档需要特殊的样式时,就应该使用内部样式表。你可以使用 <style> 标签在文档头部定义内部样式表
<head>
<style>
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/back40.gif");}
</style>
</head>
3)内联样式(Inline style)
由于要将表现和内容混杂在一起,内联样式会损失掉样式表的许多优势。请慎用这种方法,例如当样式仅需要在一个元素上应用一次时。
要使用内联样式,你需要在相关的标签内使用样式(style)属性。Style 属性可以包含任何 CSS 属性
<p style="color:sienna;margin-left:20px">这是一个段落。</p>
注:除此以外还有多重样式,即将三种方法混合使用,多重样式的优先级:(内联样式)Inline style > (内部样式)Internal style sheet >(外部样式)External style sheet > 浏览器默认样式
6.CSS background
CSS 属性定义背景效果:
- background-color
- background-image
- background-repeat
- background-attachment
- background-position