创建HTML文档
!DOCTYPE HTML
HTML创建文档的固定开头。
head、bady
HTML文档的(head)头文件和(bady)身体文件。
head里面主要有title、base、meta、link、script、noscript
bady里面的内容就是页面需要呈现的内容。
title
html文档在浏览器中的标题
<title>Example</title>
base
用于设置一个基准URL,让HTML文档中的相对链接在此基础上进行解析。若不设置,则默认基准URL为该网页地址。
<base href="http://www.baidu.com" />
meta
meta--name、content
用于使用名/值对定义元数据。
<meta name="author" content="Luomu">
<meta name="description" content="A simple example">
<meta name="keywords" content="student,study,html">
meta--charset
用于声明HTML文档内容所用的字符编码
<meta charset="utf-8">
meta--http-equiv
http-equiv属性拥有三种模拟或替换标头的字段,分别是refresh、default-style、content-type
refresh是用于跳转到领一网页或者刷新原有页面。
<meta http-equiv="refresh" content="5;https://www.baidu.com" />
表示五秒后跳转到百度网页
<meta http-equiv="refresh" content="5" />
表示5秒后刷新网页
-
default-style表示指定页面优先使用的样式表。对应的content属性值与同一文档中某个style元素或者link元素的title属性值相同。 -
content-type是另一种声明HTML文档内容所用的字符编码
<meta http-equiv="content-type" content="text/html charset=URF-8">
style
用于定义HTML文档内嵌的css样式。
<style type="text/css">
a{
background:grey;
color:white;
padding:0.5me;
}
</style>
media
用于指定样式使用的媒体。符合规定的值有all所有设备;handheld手持设备;print打印预览和打印设备;screen计算机屏幕。
<style media="screen" type="text/css">...</style>
<style media="print" type="text/css">...</style>
<style media="handheld" type="text/css">...</style>
media的值还可以更具体一些,例如
<style media="screen AND (max-width:500px)" type="text/css">
表示当浏览器的宽度大于500px时,应用这个样式。
link
用于在HTML文档和外部资源之间建立联系,主要用于链接css样式表。
link元素的属性有
rel文档与关联资源的关系类型;href指定link元素指向的资源的URL;hreflang说明关联资源使用的语言;media所关联的内容用于哪种设备;sizes指定图标的大小;type指定所关联资源的MIME类型。如text/css、image/x-icon
link--rel
rel表示文档与关联资源的关系类型,类型种类有
alternate连接到文档的替代版本;author连接到文档的作者;help连接到文档的说明文档;icon链接到指定图标资源;license链接到当前文档的相关许可证;pingback指定一个回探服务器;prefetch预先获取一个资源;stylesheet载入外部样式表。
<link rel="stylesheet" href="styles.css" type="text/css" /> 链接外部css样式
<link rel="shortcut icon" href="Luomu.ico" type="image/x-ico" /> 给网页添加一个ico图标
<link rel="prefetch" href="/page2.html" /> 预先获取关联的资源
script
用于在文档中定义脚本或者引用外部脚本。 属性值有
src指定外部脚本的URL。defer、async设定脚本的执行方式延时、异步。只能与src属性一同使用charset说明外部文件字符编码类型。只能与src属性一同使用type引用脚本的类型
script--内嵌脚本
<script>
docyment.write("This is from the script")
</script>
script--载入外部脚本(延时/异步)
<script defer src="simple.js"></script>
<script async src="simple.js"></script>
noscript
当用户禁用了JavaScript或浏览器不支持JavaScript时显示相关内容。
当禁止使用JavaScript时,在页面上进行提示。
<noscript>
<h1>Javascript is required!</h1>
</noscript>
当禁止使用JavaScript时,跳转到另一个网页
<noscript>
<meta http-equiv="refresh" content="0;https://www.baidu.com" />
</noscript>