HTML 知识速查
快速查找HTML基本标签的用法,提供一些信息平台常用的class。
快速查找HTML基本标签的用法,提供一些信息平台常用的class。
超文本标记语言(英语:HyperText Markup Language,简称:HTML)是一种用于创建网页的标准标记语言。 您可以使用 HTML 来建立自己的 WEB 站点,HTML 运行在浏览器上,由浏览器来解析。
该培训文档从零开始讲解,包含了 基础知识、常见问题和作业。HTML 很容易学习!相信您能很快学会它!
<h1>
,第二个标签是 结束标签,如 </h1>
<p> 段落 </p>
和 <b> 粗体 </b>
<hr/> 水平线
、<br/> 换行
和 <img/> 图片
<div class="container wd">
text </div>
<a href="..." class="mylink red-text">
text </a>
<img src="..." class="img-responsive"/>
市场信息人员只需要了解结构,不需要编写。
<!DOCTYPE html>
表示 HTML5 文档<html>
表示HTML页面的根元素<head>
表示页面的元(meta)数据,Google会抓取,对应信息平台的 SEO描述、SEO关键字<title>
表示页面的标题,显示在浏览器的标签卡上,对应信息平台的 SEO标题<body>
表示可见的页面内容,对应信息平台的 信息内容<!-- 注释内容 -->
表示注释,页面上不可见的内容。
在信息平台删除标签或内容时,推荐使用注释,而不是直接删除
<!DOCTYPE html>
<html>
<head>
<title>文档标题</title>
<meta />
</head>
<body>
可见部分,即整个页面文档
<!-- 注释内容,不可见 -->
</body>
</html>
标题(Heading)是通过 <h1> - <h6>
标签进行定义的.
<h1>
定义最大的标题。 <h6>
定义最小的标题。
搜索引擎使用标题做为网页结构和内容的索引。
应该将 <h1>
用作主标题(最重要的并且是唯一的),其后是 <h2>
(次重要的),再其次是 <h3>
,以此类推。
h1. 标题 简短描述 |
h2. 标题 简短描述 |
h3. 标题 简短描述 |
h4. 标题 简短描述 |
h5. 标题 简短描述 |
h6. 标题 简短描述 |
<h1>h1. 标题 <small>简短描述</small></h1>
<h2>h2. 标题 <small>简短描述</small></h2>
<h3>h3. 标题 <small>简短描述</small></h3>
<h4>h4. 标题 <small>简短描述</small></h4>
<h5>h5. 标题 <small>简短描述</small></h5>
<h6>h6. 标题 <small>简短描述</small></h6>
一个页面有唯一的 <h1>
,然后有 <h2>
、<h3>
,
不推荐在没有 <h2>
的情况下,直接使用 <h3>
。
作业
<p>
表示一个段落,通常与这些标签联用:换行 <br>
,水平线 <hr>
,加粗 <strong>
p. 这是段落1
p. 这是段落2
这个
段落
演示了分行的效果
段落换行
<p> p. 这是<strong>段落1</strong> </p>
<p> p. 这是<strong>段落2</strong> </p> <hr>
<p> 这个<br>段落<br>演示了分行的效果 </p>
默认下,段落和段落存在有一定间隔,类似于 WORD 的行间距。注意:如果通过 <br>
来换行,那么就没有行间距了。
作业
<p>
使用预设的 class
属性进行排版,优秀的排版可以让文章更易读
一般说明:浅蓝底色 (class="bg-info")
强调说明:橙色底色 (class="bg-warning")
左对齐 (class="text-left")
居中对齐 (class="text-center")
右对齐 (class="text-right")
两边对齐 (class="text-justify")
名人名言、wiki引用、规章制度
段落高亮
<p class="bg-info">一般说明:浅蓝底色</p>
<p class="bg-warning">一般说明:橙色底色</p>
段落文字对齐
<p class="text-left"> 左对齐 </p>
<p class="text-center"> 居中对齐 </p>
<p class="text-right"> 右对齐 </p>
<p class="text-justify"> 两边对齐 </p>
垂直排列的描述
<dl>
<dt>...</dt>
<dd>...</dd>
</dl>
水平排列的描述
<dl class="dl-horizontal">
<dt>...</dt>
<dd>...</dd>
</dl>
外部引用
<blockquote>
<p>名人名言、wiki引用、规章制度</p>
<footer>原作者、来源、wiki</footer>
</blockquote>
根据内容的结构,选择合适的标签,便于开发者阅读的同时让搜索引擎(Google)更方便的解析页面。
作业
链接可以是一个字,一个词,或者一组词,也可以是一幅图像,您可以点击这些内容来跳转到新的文档或者当前文档中的某个部分。 当您把鼠标指针移动到网页中的某个链接上时,箭头会变为一只小手。
<a>
标签里面的 href="url"
,表示点击后在当前标签页打开url。
<a>
标签里面的 target="_blank"
,表示使用新标签页打开链接。
<a>
可以放在文章中间,例如 a. 链接1 当前标签页打开BBC。
<a>
默认在当前标签页打开,可以配置 <a>
属性 target="_blank"
,如 a. 链接2 新标签页打开BBC。
文字链接
可以放在文章中间,例如 <a href="http://www.bbc.com/" > a. 链接1 当前标签页打开BBC </a>
默认在当前标签页打开,可以配置 <a href="http://www.bbc.com/" target="_blank"> a. 链接2 新标签页打开BBC </a>
图片链接
<a href="http://www.bbc.com/" target="_blank">
<img src="http://data.chinahighlights.com/image/homepage/the-bund.jpg" class="img-responsive" alt="The Bund">
</a>
没有文字或图片的链接,例如: <a href="..." > </a>
,请删除空链接。
记住: <a href="..." > ... </a>
必须成对出现,且中间必须有文字或者图片
href="..."
的规则?
如果链接到外站页面,需要写全url,例如 href="http://www.baidu.com"
;
如果链接到本站页面,只需要写域名后面的那部分,例如 href="/travelguide/chinese-culture-facts.htm"
.
作业
在 HTML 中,图像由 <img>
标签定义。
<img>
是单标签,意思是说,它只包含属性,并且没有闭合标签。
要在页面上显示图像,你需要使用源属性(src
)。src
指 "source"。src
属性的值是图像的 URL
地址。
根据HTML5规范:alt
属性用来为图像定义一串预备的可替换的图片描述文本。
注意:google给了 alt
新的含义:它会收录在google图片搜索索引里面,因此重要的信息图片务必加上 alt
属性。
推介信息的主题图片保持和信息标题一致!-前提:图片确实与信息主题相关。
正常的图片应该包含 图片地址 src
,响应式类 class="img-responsive"
, 图片描述 alt
, 图片标题 title
。
就像这样:
<img src="http://data.chinahighlights.com/image/citytour/guilin-tours/hiking.jpg" class="img-responsive" alt="漓江" />
class="img-responsive"
class="img-responsive img-rounded"
class="img-responsive img-circle"
class="img-responsive img-thumbnail"
响应式图片
<img src="..." class="img-responsive" alt="漓江" />
圆角图片
<img src="..." class="img-responsive img-rounded" alt="漓江" />
圆形图片
<img src="..." class="img-responsive img-circle" alt="漓江" />
边框图片
<img src="..." class="img-responsive img-thumbnail" alt="漓江" />
添加了 class="img-responsive"
的图片,不需要再添加:宽 width="200"
和高 height="200"
属性。
添加了 class="img-responsive"
的图片,会自适应设备的大小来调整高宽。
如果想看图片的原始高宽,可以使用chrome右键图片选择“检查”,鼠标移动到页面下方控制台区域的图片URL地址处,chrome会显示图片快照、显示大小及原始大小。
作业
图片通常放在 <p>
、<div>
与文字放在一起进行排版,即:“图文混排”。
图片对齐:左对齐,居中,右对齐
class="pull-left"
The classic picture in people's mind is the Li River in mist. This scenery appears most from April to
June.
In April it usually drizzles all day long and you may not see the scenery clearly on the river. In May
and June the rainfall is more violent, often as stormy downpours! You may need to hold an umbrella on
the deck, which is inconvenient to enjoy the scenery. An excellent time to see mist hugging the hills
is early on a warm morning after a night of rain.
This period is the best time to see the scenery along the river clearly.
class="pull-right"
The classic picture in people's mind is the Li River in mist. This scenery appears most from April to
June.
In April it usually drizzles all day long and you may not see the scenery clearly on the river. In May
and June the rainfall is more violent, often as stormy downpours! You may need to hold an umbrella on
the deck, which is inconvenient to enjoy the scenery. An excellent time to see mist hugging the hills
is early on a warm morning after a night of rain.
This period is the best time to see the scenery along the river clearly.
class="center-block"
The classic picture in people's mind is the Li River in mist. This scenery appears most from April
to June.
In April it usually drizzles all day long and you may not see the scenery clearly on the river. In May
and June the rainfall is more violent, often as stormy downpours! You may need to hold an umbrella on
the deck, which is inconvenient to enjoy the scenery. An excellent time to see mist hugging the hills
is early on a warm morning after a night of rain.
This period is the best time to see the scenery along the river clearly.
图片左浮动
<p>
<img src="..." class="img-responsive pull-left" alt="桂林漓江" title="桂林漓江" />
...text
</p>
<div class="clearfix"></div>
图片右浮动
<p>
<img src="..." class="img-responsive pull-right" alt="桂林漓江" title="桂林漓江" />
...text
</p>
<div class="clearfix"></div>
图片居中
<p>
<img src="..." class="img-responsive center-block" alt="桂林漓江" title="桂林漓江" />
...text
</p>
<div class="clearfix"></div>
在下一个标题前,应该清除上一个标题所属段落的图片浮动。在下一个标题前面加上
<div class="clearfix"></div>
作业
<ul>
标签表示 HTML无序列表,使用 class="ul"
修饰。
<ol>
标签表示 HTML有序列表,使用 class="ol"
修饰。
<li>
中间可以是文本,链接,图片。
无序列表
<ul class="ul">
<li>不要了, 谢谢 (búyàolē, xièxiè): No, thanks.</li>
<li>这个多少钱 (zhègè duōshǎo qián): How much is this?</li>
<li>太贵了 (tàiguì lē): It is too expensive.</li>
<li>少点吧 (shǎodiǎn bā), or 便宜点 (piányì diǎn): Can you come down a bit?</li>
</ul>
有序列表
<ol class="ol">
<li>Reddit</li>
<li>Weibo</li>
<li>Twitter</li>
<li>Facebook</li>
<li>Youtube</li>
</ol>
<ul>
或 <ol>
必须包含 <li>
;<li>
也必须放在 <ul>
或 <ol>
下面,否则无效。
作业
HTML <div>
是区块标签,它其实是组合其他HTML标签的盒子,并且已经组装好的盒子也可以放在其他盒子里面,最后组装成一个HTML页面。
例如:我们可以把多个 <h3>
、<img>
、<p>
标签按照指定的 顺序
放进一个 <div>
盒子里面,组成一个带文字的照片区块。
标签卡
<div class="panel panel-default">
<div class="panel-heading">Traffic and Air pollution</div>
<div class="panel-body">
On top of the traffic, air pollution and the smog can also be an assault on the senses. While reports in the Western media may sometimes make it seem like the air in China is constantly bad, there are bad days and good days. Northern China tends to be hit by pollution more, especially during the long winter months, and on bad days you may want to wear a face mask to protect yourself.
</div>
</div>
照片墙
<div class="thumbnail">
<img src="http://data.chinahighlights.com/image/china-tour/giant-panda.jpg" class="img-responsive" alt="熊猫">
<div class="caption">
<h3>TGiant Pandas</h3>
<p>Enjoy all the classic wonders in Beijing, Xi’an, and Shanghai; relax on board the Yangtze River cruise; treat yourself to the highlight of the tour — the one-day Panda Keeper Program at Dujiangyan Panda Base in Chengdu.</p>
<p><a href="#" class="btn btn-primary" >Like it!</a> <a href="#" class="btn btn-default" >But it!</a></p>
</div>
</div>
<div>
和结束标签</div>
?
使用HTML编辑器(信息平台的编辑器、dreamwaver)的代码模式。此模式下,<div>
左边会有一条垂直的虚线,沿着这条虚线则可以找到对应的闭合标签 </div>
。
通常在 <div>
左边会有一个黑色的倒三角,可以折叠 简单的 <div>
区块。注意:复杂的
<div>
不能正常折叠。
第一步,和技术(设计)沟通你想要的盒子效果,让他们帮你设计和组装。
第二步,取出技术组装好并放入信息平台的HTML标签代码,复制到你编写的信息中。
作业