本文主要和大家分享对html基本语法和语义进行了整理与实例,需要的朋友可以参考下,希望能帮助到大家。
doctype
doctype(document type)
该声明位于文档中最前面的位置,处于html标签之前,此标签告知浏览器文档使用哪种html或者 xhtml规范。
dtd(document type definition)
声明以1a309583e26acea4f04ca31122d8c535开始,不区分大小写,前面没有任何内容,如果有其他内容(空格除外)会使浏览器在ie下开启怪异模式(quirks mode)渲染网页。公共dtd,名称格式为注册//组织//类型 标签//语言,注册指组织是否由国际标准化组织(iso)注册,+表示是,-表示不是。组织即组织名称,如:w3c。类型一般是 dtd。标签是指定公开文本描述,即对所引用的公开文本的唯一描述性名称,后面可附带版本号。最后语言是dtd语言的iso 639语言标识符,如:en表示英文,zh表示中文。xhtml 1.0 可声明三种dtd 类型。分别表示严格版本,过渡版本,以及基于框架的html文档。
html 4.01 strict
ab540a5be9b0ab2c90344bc442e25cc5
html 4.01 transitional
c22098bfd3f62d7436149aaab013de1a
html 4.01 frameset
d44b1c13b51eddec01ecbde9e66f5216
html5文档类型
8b05045a5be5764f313ed5b9168a17e682e535b3f4e9f6fb9559d510cf4cacf8
meta
声明文档使用的字符编码
html5之前
<meta http-equiv="content-type" content="text/html; charset=utf-8">
html5
<meta charset="utf-8">
seo优化
标题
<title>your title</title>
页面描述
<meta name="description" content="your description">
关键字
<meta name="keywords" content="your keywords">
网页作者
<meta name="author" content="your name">
网页搜索引擎索引方式
<meta name="robots" content="index,follow">
follow 跟踪链接并分析目标网页。这是默认行为,并且可忽略。
index 将网页编入索引。这是默认行为,并且可忽略。
noodp 不使用 open directory project 来创建内容描述。
noydir 不使用 yahoo directory 来创建内容描述。
noarchive 不允许搜索引擎显示内容的缓存版本。
cache 允许搜索引擎显示内容的缓存版本。
nocache 不允许搜索引擎显示内容的缓存版本。
标签
定义文档的结构,使文档的标记更加语义化。
html5 demo
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>html5 demo</title>
</head>
<body>
<header>
<h1>html5 demo</h1>
<nav>
<ul>
<li>nav1</li>
<li>nav2</li>
</ul>
</nav>
</header>
<section>
<h1>article aside</h1>
<article>article</article>
<aside>aside</aside>
<section>
<footer>footer</footer>
</body>
</html>
tips
html5标签更加丰富和完善,p标签似乎没有什么用武之地,但是如果仅仅想在文档中加入一段样式,这个时候p标签便派上用场了。
标签在不同浏览器默认样式会有一些区别,为了一个网页在不同浏览器中看到的效果一样,通常要先格式化一下标签的样式
@charset "utf-8";
html{margin:0;padding:0;border:0}a,abbr,acronym,address,article,aside,blockquote,body,caption,code,dd,del,dfn,dialog,p,dl,dt,em,fieldset,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,iframe,img,label,legend,li,nav,object,ol,p,pre,q,section,span,table,tbody,td,tfoot,th,thead,tr,ul{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details,dialog,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1.5;background:#fff}table{border-collapse:separate;border-spacing:0}caption,td,th{text-align:left;font-weight:400;float:none!important}table,td,th{vertical-align:middle}blockquote:after,blockquote:before,q:after,q:before{content:''}blockquote,q{quotes:"" ""}a img{border:none}a{text-decoration:none}:focus{outline:0}
如果要在不支持html5的浏览器中使用html5标签,需要加一小段javascript代码
<script>
document.createelement('header');
document.createelement('nav');
document.createelement('section');
document.createelement('aside');
document.createelement('article');
document.createelement('footer');
</script>
标签可编辑属性contenteditable
5148c1b640285f5056f70cb723d5fb367618f95bdc39e398f223d37049478af1
相关推荐:
解析html基本语法和语义写法规则
javascript中正则表达式的使用及基本语法_正则表达式
html基本语法和语义写法规则与实例
以上就是关于html基本语法和语义写法规则与实例分析的详细内容。
