HTML基本语法和语义写法规则与实例 |
DOCTYPE DOCTYPE(Document Type) 该声明位于文档中最前面的位置,处于html标签之前,此标签告知浏览器文档使用哪种HTML或者 XHTML规范 。 DTD(Document Type Definition) 声明以 HTML 4.01 strict
HTML 4.01 Transitional
HTML 4.01 Frameset
HTML5文档类型
meta 声明文档使用的字符编码 html5之前 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> html5 <meta charset="utf-8"> SEO优化 标题
页面描述
关键字
网页作者
网页搜索引擎索引方式
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标签更加丰富和完善,div标签似乎没有什么用武之地,但是如果仅仅想在文档中加入一段样式,这个时候div标签便派上用场了 。 标签在不同浏览器默认样式会有一些区别,为了一个网页在不同浏览器中看到的效果一样,通常要先格式化一下标签的样式 @charset "utf-8"; html{margin:0;padding:0;border:0}a,abbr,acronym,address,article,aside,blockquote,body,caption,code,dd,del,dfn,dialog,div,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
以上文章内容希望对各位朋友有所帮 |