在HTML页面的头部申明字符为 UTF-8 可以解决在浏览器中出现中文乱码的现象。
xxxxxxxxxx41<head>2 <meta charset="UTF-8">3 <title>页面标题</title>4</head>HTML 标题:通过 <h1> - <h6> 标签来定义。
xxxxxxxxxx41<h1>一级标题</h1>2<h2>二级标题</h2>3...4<h6>三级标题</h6>HTML 段落:通过 <p> 标签来定义。
xxxxxxxxxx21<p>这是一个段落。</p>2<p>这是另一个段落。</p>HTML 链接:可以跳转到外部链接地址,也可以链接到当前页面的某部分实现内部导航功能。
xxxxxxxxxx41<a href="#">空连接</a>2<a href="https://www.w3cschool.cn">w3cschool</a> //链接到外部地址3<div id="ct1">词条1</div> //跳转到页面内部,用 #id 链接4<a href="#ct1">跳转到词条1</a>HTML 图像:通过 <img> 标签来定义。
xxxxxxxxxx11<img src="https://www.your-image-source.com/your-image.jpg"> //img是自关闭元素,不需要结束标记HTML 格式化:
文本格式化
xxxxxxxxxx81<b>这个文本是加粗的</b> //加粗2<strong>这个文本也是加粗的</strong> //加粗,并表示文本重要3<i>这个文本是斜体的</i> //斜体4<em>这个文本是斜体的</em> //斜体,并表示文本重要5<big>这个文本字体放大</big> //字体放大6<small>这个文本是缩小的</small> //字体缩小7这个文本包含<sup>上标</sup> //上标8这个文本包含<sub>下标</sub> //下标预文本格式化
xxxxxxxxxx51<pre> //pre标签保存文本中的空行和空格2此例样式如何使用 pre 标签 3对 空行 和 空格4进行控制5</pre>"计算机输出"标签
xxxxxxxxxx61//这些标签常用语显示 计算机/编程 代码2<code>计算机输出</code> //计算机输出3<kbd>键盘输入</kbd> //键盘输入4<tt>打字机文本</tt> //打字机文本5<samp>计算机代码样本</samp> //计算机代码样本6<var>计算机变量</var> //计算机变量地址
xxxxxxxxxx41<address> //表示地址2Written by XXXX3yyyyy4</address>缩写和首字母缩写
xxxxxxxxxx21<abbr title="etcetera">etc</abbr> //缩略词,用title表示2<acronym title="World Wide Web">WWW</acronym>文字方向
xxxxxxxxxx51<p>该段文字从左到右显示</p> //默认从左到右2<p> //用bdo+dir从右到左显示3 <bdo dir="rtl">该段文字从右到左显示</bdo> //ltr左,rtl右 4</p>5<p dir="rtl">从左到右靠右端对其显示</p> //从左到右,靠右侧对其显示块引用
xxxxxxxxxx71<p> //用<q>来定义短的引用语2 WWF's goal is to:3 <q>AAAAA</q>,4 <q>BBBBB</q>,5 <q>CCCCC</q>6 We hope they succeed.7</p>删除字效果和插入字效果
xxxxxxxxxx21<del>删除字</del> //删除字2<ins>插入字</ins> //插入字HTML 头部
title:定义了HTML文档的标题
xxxxxxxxxx31<head>2 <title>页面标题</title>3</head>base:定义了所有链接的URL
xxxxxxxxxx61<head>2 <base href="https://www.w3cschool.cn/statics/images/w3c/" target="_blank">3</head>4<body>5 <img src="logo.png">6</body>meta:提供了HTML文档的meta标记
xxxxxxxxxx71<head>2<title>W3Cschool(w3cschool.cn)</title> 3<meta name="description" content="免费web教程">4<meta name="keywords" content="HTML,CSS,XML,JavaScript">5<meta name="author" content="W3Cschool">6<meta charset="UTF-8">7</head>HTML CSS
内联样式 - 在HTML元素中使用"style"属性。
xxxxxxxxxx31<p style="color:blue;margin-left:20px">2 This is a garagraph.3</p>内部样式表 - 在HTML文档头部 <head>区域使用 <style>元素来包含 CSS 。
xxxxxxxxxx61<head>2 <style type="text/css">3 body {background-color: yellow;}4 p {color: blue;}5 </style>6</head>外部引用 - 使用外部 CSS 文件。
xxxxxxxxxx31<head>2 <link rel="stylesheet" type="text/css" href="mystyle.css">3</head>HTML 表格
xxxxxxxxxx61<table border="0"> //定义表格+无边框2 <tr> //定义表格的行3 <th>这是表头</th> //定义表格的表头4 <td>这是单元格</td> //定义表格单元5 </tr>6</table>xxxxxxxxxx41<td colspan="2">AAA</td> //跨2列的单元格2<tr rowspan="3"> //跨3行的单元格3 <td>BBB</td>4</tr>xxxxxxxxxx31<table border="1" >...</table> //单元格间距2<table cellpadding="0">...</table> //单元格边距3<table cellspacing="0">...</table> //单元格间距(0时单元格边框为一条细线)HTML 列表
无序列表
xxxxxxxxxx61<ul>2 <li>coffee</li>3 <li>milk</li>4 <li>...</li>5</ul>6// css样式可修改:list-style-type:disc,circle,square有序列表
xxxxxxxxxx71<ol>2 <li>coffee</li>3 <li>milk</li>4 <li>...</li>5</ol>6// ol 可加属性 type="A,a,I,i"7// ol 可加属性 start="number",只能是数字,H5不推荐自定义列表
xxxxxxxxxx61<dl> //自定义列表开始2 <dt>Coffee</dt> //自定义列表项3 <dd> - black hot drink</dd> //自定义列表项定义4 <dt>Milk</dt>5 <dd> - white cold drink</dd>6</dl>HTML 区块
xxxxxxxxxx21区块元素:自动换行,可设定宽度,<h1>,<p>,<ul>,<table>,<div>等2内联元素:不自动换行,不可设定宽度,<b>,<td>,<a>,<img>,<span>等
HTML 布局
xxxxxxxxxx81<div>2 <div style="float:left">3 <b>我在左边</b>4 </div>5 <div>6 <b>我在右边</b>7 </div>8</div>HTML 表单
xxxxxxxxxx331<form action="xxx" method="post"> //定义表单2 <fieldset> //定义带边框的表单,非必须3 <legend> //和fieldset一起使用,表示边框标题4 表单边框标题5 </legend>6 //表单控件7 user:<input type="text" name="user">8 password:<input type="password" name="password">9 //单选10 <input type"radio" name="sex" value="male">Male<br>11 <input type="radio" name="sex" value="female">Female<br>12 //多选13 <input type="checkbox" name="vehicle" value="Bike">I have a bike <br>14 <input type="checkbox" name="vehicle" value="Car">I have a car<br>15 //简单下拉框16 <select name="cars">17 <optgroup label="Swedish Cars"> //选项分组118 <option value="volvo">Volvo</option>19 <option value="saab">Saab</option>20 </optgroup>21 <optgroup label="German Cars"> //选项分组222 <option value="mercedes">Mercedes</option>23 <option value="audi" selected>Audi</option> //默认选中值24 </optgroup>25 </select>26 //文本域27 <textarea rows="10" cols="50"> 28 我是一个文本框。29 </textarea>30 //提交按钮(url在form上配置)31 <input type="submit" value="提交">32 </fieldset>33</form>xxxxxxxxxx51//label 元素的使用,点击label元素,等同于点击对应的表单控件2<form action="xxx" method="post">3 <label for="ma">Male</label><input type="radio" name="sex" value="male" id="ma"><br>4 <label for="fe">Female</label><input type="radio" name="sex" value="female" id="fe">5</form>HTML 框架
xxxxxxxxxx41<iframe src="demo_iframe.html" name="iframe_a"></iframe> //定义iframe2<p>3 <a href="https://www.w3cschool.cn" target="iframe_a">W3CSCHOOL.CN</a> //target表示链接在iframe框架中打开4</p>HTML 字符实体
xxxxxxxxxx31< 等同于 <2> 等同于 >3© 等同于 ©
HTML URL
xxxxxxxxxx11scheme://host.domain:port/path/filename
说明
插件可以使用 <object> 和 <embed> 标签来显示,两者效果都是类似,可用于插入对象(音频,视频,HTML页面,Java小程序,PDF 阅读器,Flash 播放器等),区别是:
object :HTML4 的标准标签, <param> 配合使用。
embed:HTML5 的新标签,在HTML4 中是非法的。
所以,两者一般一起使用,确保能兼容 新旧 浏览器。
xxxxxxxxxx111<body>2 <object width="550" height="400" data="heartbeats.mp3"></object>3 <embed width="550" height="400" src="heartbeats.mp3">4 //合并使用5 <object width="550" height="400" src="headerbeats.mp3">6 <param name=moive value="myflashmovie.swf">7 <param name=quality value="high">8 <param name=bgcolor value="#ffffff">9 <embed src="heartbeats.mp3">10 </object>11</body>Audio:音频文件
使用 <audio> 和 <source> 标签来定义音频。
<audio> 是一个 HTML5 元素,在 HTML4 中是非法的,但在所有浏览器中都有效。
一般和 <embed> 一起使用,保证兼容性。
xxxxxxxxxx51<audio controls height="100" width="100">2 <source src="horse.mp3" type="audio/mpeg">3 <source src="horse.mp3" type="audio/ogg">4 <embed height="50" width="100" src="horse.mp3">5</audio>Videos:视频文件
使用 <video> 和 <source> 标签来定义视频。
<video> 是一个 HTML5 元素,在 HTML4 中是非法的,但在所有浏览器中都有效。
一般和 <object> , <embed> 一起使用,保证兼容性。
xxxxxxxxxx81<video width="320" height="240" controls>2 <source src="moive.mp4" type="video/mp4">3 <source src="moive.ogg" type="video/ogg">4 <source src="moive.webm" type="video/webm">5 <object data="moive.mp4" width="320" height="240" >6 <embed src="moive.swf" width="320" height="240">7 </object>8</video>常用代码
xxxxxxxxxx81//超链接设置2text-decoration:参数3参数取值范围4underline:为文字加下划线5overline:为文字加上划线6line-through:为文字加删除线7blink:使文字闪烁8none:不显示上述任何效果
常用标签:见 CSS.md 文档。