How to enable IE to support HTML5 _ html5 tutorial skills-

Source: Internet
Author: User
More and more sites are using HTML5 tags, but there are still many users using IE6, IE7, and ie8. To enable normal access to all viewers, more and more websites are using HTML5 tags. However, many users are currently using IE6, IE7, and ie8. To enable normal access for all viewers, there are two solutions:

1. Create multiple templates for the website. The User-Agent can be judged by a program to display different pages for different browser users, for example, Youku.

2. Use Javascript to support HTML tags in browsers that do not support HTML5.

The better solution for IE is html5shiv. Htnl5shiv mainly solves the problem that the new elements proposed by HTML5 are not recognized by the IE6-8. These new elements cannot wrap child elements as parent nodes and cannot apply CSS styles. To apply CSS styles to unknown elements, you only need to execute document. createElement (elementName. Html5shiv is created based on this principle.

Html5shiv is very simple to use. Considering IE9 supports html5, you only need to add the following code to the page head:

The Code is as follows:




After the preceding code is added, the following results are displayed in IE8:

The JavaScript code for creating nodes in the sitepoint example seems too bloated, and the Code provided in smashingmagazine seems more concise.
The demo is as follows:


<! DOCTYPE html> <ptml lang = "en"> <pead> <meta charset = UTF-8> <! -- Simplified version; works on legacy browsers --> <title> Basic styling of new structural tags </title> <style> * {margin: 0; padding: 0 ;} body {background-color: white; color: black; text-align: center;} header, footer, nav, section, article {display: block;} header {width: 100%; background-color: yellow;} nav {width: 30%; background-color: orange; float: left;} section {width: 65%; background-color: SpringGreen; f Loat: right;} article {width: 70%; margin: 2em 10%; background-color: turquoise;} footer {width: 100%; background-color: pink; clear: both ;} </style> <! -- [If IE]> script (function () {if (! /* @ Cc_on! @ */0) return; var e = "abbr, article, aside, audio, bb, canvas, datagrid, datalist, details, didio, eventsource, figure, footer, header, hgroup, mark, menu, meter, nav, output, progress, section, time, video ". split (','), I = e. length; while (I --) {document. createElement (e [I]) }}() script <! [Endif] --> <body> <peader> Hello </peader> <nav> <p> Menu </p> </nav> <section> <p> Section </ p> <p> article 1 </p> </article> <p> article 2 </p> </article> </section> <footer> <p> The footer </p> </footer> </body> </ptml>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.