The Semantic tags and attributes of HTML5 make it easy for developers to easily achieve a clear web page layout. With the help of CSS 3 rendering, it is very easy to quickly build a rich and flexible web page.
HTML5 new tag elements include:
- <Header> define the header of a page or segment;
- <Footer> defines the end of a page or segment;
- <Nav> define the navigation area of a page or segment;
- <Section> logical area or content combination of the page;
- <Article> define the body or a complete content;
- <Aside> define supplementary or related content;
They canCodeThe semantics is more intuitive, and Seo optimization is more convenient. However, this HTML5 new tag cannot be identified on IE6, IE7, or IE8 and needs JavaScript processing. The following describes several methods.
Method 1: Coding Javascript
<! --[ If Lt ie9]> <SCRIPT> ( Function (){ If (! /* @ Cc_on! @ */ 0) Return ; VaR E = "abbr, article, aside, audio, canvas, datalist, details, dialog, eventsource, figure, footer, header, hgroup, Mark, menu, meter, NAV, output, progress, section, time, video ". split (',' ); VaR I = E. length; While (I -- ) {Document. createelement (E [I])}) () </SCRIPT> <! [Endif] -->
For ie browsers under ie9, HTML5 tags will be created, so that non-ie browsers will ignore this code and there will be no unnecessary HTTP requests.
Method 2: Use Google's html5shiv package (recommended)
<! --[If<Ie9]> <SCRIPT src = "http://html5shiv.googlecode.com/svn/trunk/html5.js"> </SCRIPT> <! [Endif] -->
However, no matter which method is used, the CSS of the new tag must be initialized. because HTML5 is represented by inline elements by default, we need to use CSS to manually convert these elements into block elements for easy layout.
/*HTML5*/Article, aside, dialog, footer, header, section, footer, NAV, figure, menu{Display:Block}
However, if IE6/7/8 disables the script, it will become a "whiteboard" webpage without style. How can we solve this problem?
We can refer to Facebook'sThe method is to guide the user into"/? _ Fb_noscript = 1"Page, use html4 tags to replace HTML5 tags, Which is lighter than writing a large number of hack to maintain compatibility.
<! --[If lte ie 8]> <NoScript> <style>. html5-wrappers {display: none! Important ;}</style> <Div class = "ie-NoScript-warning"> scripts are disabled in your browser, please <a href = ""> check here </a> to enable the script! Or <a href = "/? NoScript = 1 "> continue access </a>. </div> </NoScript> <! [Endif]-->
In this way, the user can be guided to open the script or directly jump to the HTML 4 tag design interface.