Web技术的发展速度太快了,如果你不与时俱进,就会被淘汰。因此,为了应对即将到来的HTML 5,本文总结了11个HTML 5的初级技巧,希望能对你进一步学习好HTML 5会有所帮助。
1. 新的Doctype声明
XHTML的声明太长了,我相信很少会有前端开发人员能手写出这个Doctype声明。
nbsp; "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
HTML 5的Doctype声明很短,看到这个声明相信你马上就能记住,不用浪费脑细胞去记那长的有点变态的XHTML的Doctype声明了。
HTML 5的简短的DOCTYPE声明是让Firefox、Chrome等现代浏览器和IE6/7/8等浏览器都进入(准)标准模式,你可能会奇怪IE6/7居然也可以支持HTML 5 Doctype,事实上,IE是只要doctype符合这种格式,都会进入标准模式。
2.
看看下面一段简单的代码:
遗憾的是,这里的h6标签和img标签好像没有什么关系,语义不够明确。HTML 5意识到了这一点,于是就采用了
This is an image of something interesting.
3. 重新定义
不久前,我使用了标签来创建与logo相关的副标题。但是在HTML 5中重新定义了标签,使之更能表现语义化,在的字号都会变小,想想如果这个标签用于网站的底部的版权信息还是个不错的做法。
4. 去掉了Javascript和CSS标签的type属性
通常你会在和<script>加上type属性:</script>
在HTML 5中,不再需要type属性了,因为这显得有点多余,去掉之后可以让代码更为简洁。
5. 是否使用双引号
这有点让人纠结,HTML 5并不是XTHML,你可以省去标签中的双引号。相信大多数同志也包括我都习惯了加上双引号,因为这让代码看起来会更标准。不过,这可以根据你的个人喜好来确定是到底要不要双引号。
start the reactor.
6. 使网页内容可以编辑
7. 电子邮件输入框
HMTL 5中新增了一个输入框的电子邮件属性,可以检测输入的内容是否符合电子邮件的书写格式,功能越来越强大了吧,在HTML 5之前只能依靠JavaScript来检测。虽然内置的表单验证功能很快就会成为现实,但这个属性很多浏览器都还不支持,只会当作普通的文本输入框来处理。
到目前为止,包括现代浏览器在内都不支持该属性,所以这个属性暂时还是靠不住的。
8. 占位符
文本框中的占位符(看看本博的搜索框效果)有利于提升用户体验,之前,我们只能依靠JS来实现占位符的效果,在HTML 5中新增了占位符属性placeholder。
<ol class="dp-xml"><li class="alt"> <span><span class="tag-name">&</span></span>lt;<span><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"email"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"email"</span><span> </span><span class="attribute">placeholder</span><span>=</span><span class="attribute-value">"doug@givethesepeopleair.com"</span><span class="tag">&</span></span>gt;</li></ol>
同样,目前的主流现代浏览器对该属性的支持不大好,暂时只有Chrome和Safari支持该属性,Firefox和Opera不支持该属性。
9. 本地存储
HTML 5的本地存储功能,可以让现代浏览器“记住”我们输入的,就算浏览器关闭和刷新也不会受影响。虽然这个功能有些浏览器不支持,但是IE8, Safari 4, 还有 Firefox 3.5还是支持这个功能的,你可以测试下。
10. 更有语义的header和footer
下面的代码在HTML 5中将不复存在
<ol class="dp-xml"> <li class="alt"> <span><span class="tag">&</span></span>lt;<span><span class="tag"></span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">header</span><span class="tag">><br></span></span><span> ... </span> </li> <li class="alt"> <span class="tag">&</span>lt;<span class="tag">/</span><span class="tag-name">div</span><span class="tag">></span><span> <br></span> </li> <li> <span class="tag">&</span>lt;<span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">footer</span><span class="tag">></span><span> <br></span> </li> <li class="alt"><span> ... </span></li> <li> <span class="tag">&</span>lt;<span class="tag">/</span><span class="tag-name">div</span><span class="tag">&</span>gt;<br>通常我们都会给header和footer定义一个div,然后再添加一个id,但是在HTML5中可以直接使用<header>和>footer>标签,所以可以将上面的代码改写成:</header> </li> </ol>
<ol class="dp-xml"> <li class="alt"> <span><span class="tag">&</span></span>lt;<span><span class="tag"></span><span class="tag-name">header</span><span class="tag">><br></span></span><span> ... </span> </li> <li class="alt"> <span class="tag">&</span>lt;<span class="tag">/</span><span class="tag-name">header</span><span class="tag">><br></span><span class="tag">&</span>lt;<span class="tag-name">footer</span><span class="tag">></span><span> <br></span> </li> <li class="alt"><span> ... </span></li> <li> <span class="tag">&</span>lt;<span class="tag">/</span><span class="tag-name">footer</span><span class="tag">><br></span>要注意不要将这两个标签和网站的头部和页脚混淆起来,它们只是代表它们的容器。</li> </ol>
11. IE对HTML 5的支持
IE浏览器目前对HTML 5的支持并不好,也是阻碍HTML5的更快普及的一大绊脚石,不过,IE9对HTML 5的支持度还是很不错的。IE把HTML 5新增的标签都解析成内联元素,而实际上它们是块级元素,所以有必要为它们定义一个样式:
<ol class="dp-xml"> <li class="alt"><span><span>header, footer, article, section, nav, menu, hgroup { </span></span></li> <li><span> display: block; </span></li> <li class="alt"><span>} </span></li> </ol>
尽管如此,IE还是不能解析这些新增的HTML 5标签,这个时候就需要借助Javascript来解决这个问题:
<ol class="dp-xml"> <li class="alt"><span><span>document.createElement("article"); </span></span></li> <li><span>document.createElement("footer"); </span></li> <li class="alt"><span>document.createElement("header"); </span></li> <li><span>document.createElement("hgroup"); </span></li> <li class="alt"><span>document.createElement("nav"); </span></li> <li><span>document.createElement("menu"); </span></li> </ol>
你可以借助这一段Javascript代码来修复IE更好的解析HTML 5,
<ol class="dp-xml"><li class="alt"> <span><span class="tag">&</span></span>lt;<span><span class="tag"></span><span class="tag-name">script</span><span> </span><span class="attribute">mce_src</span><span>=</span><span class="attribute-value">"http://html5shim.googlecode.com/svn/trunk/html5.js"</span><span class="tag">&</span><span class="tag">&/</span><span class="tag-name">script</span><span class="tag">></span></span> </li></ol>

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.

Key elements of HTML5 include,,,,,, etc., which are used to build modern web pages. 1. Define the head content, 2. Used to navigate the link, 3. Represent the content of independent articles, 4. Organize the page content, 5. Display the sidebar content, 6. Define the footer, these elements enhance the structure and functionality of the web page.

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

How to write clean and efficient HTML5 code? The answer is to avoid common mistakes by semanticizing tags, structured code, performance optimization and avoiding common mistakes. 1. Use semantic tags such as, etc. to improve code readability and SEO effect. 2. Keep the code structured and readable, using appropriate indentation and comments. 3. Optimize performance by reducing unnecessary tags, using CDN and compressing code. 4. Avoid common mistakes, such as the tag not closed, and ensure the validity of the code.

H5 improves web user experience with multimedia support, offline storage and performance optimization. 1) Multimedia support: H5 and elements simplify development and improve user experience. 2) Offline storage: WebStorage and IndexedDB allow offline use to improve the experience. 3) Performance optimization: WebWorkers and elements optimize performance to reduce bandwidth consumption.

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools
