10-Segment Practical HTML5 code

Source: Internet
Author: User
Tags dojo toolkit

1.HTML5 Writing CSS Reset
CSS reset can also be written as reset CSS, which resets the browser style.

  1. /* html5doctor.com Reset Stylesheet (Eric Meyer ' s reset Reloaded + HTML5 baseline) v1.4 2009-07-27 | Authors:eric Meyer & Richard Clark html5doctor.com/html-5-reset-stylesheet/*/
  2. HTML, body, Div, span, object, IFRAME,
  3. H1, H2, H3, H4, H5, H6, p, blockquote, Pre,
  4. ABBR, address, cite, code,
  5. Del, DFN, EM, img, INS, KBD, Q, Samp,
  6. Small, strong, sub, SUP, VAR,
  7. b, I,
  8. DL, DT, DD, OL, UL, Li,
  9. FieldSet, form, label, legend,
  10. Table, Caption, Tbody, TFOOT, THEAD, tr, TH, TD,
  11. Article, aside, figure, footer, Header, Hgroup, menu, NAV, section, menu,
  12. Time, mark, audio, video {
  13. margin:0;
  14. padding:0;
  15. border:0;
  16. outline:0;
  17. font-size:100%;
  18. Vertical-align:baseline;
  19. Background:transparent;
  20. }
  21. Article, aside, figure, footer, header,
  22. Hgroup, nav, section {display:block;}
  23. Nav ul {list-style:none;}
  24. BLOCKQUOTE, q {quotes:none;}
  25. Blockquote:before, Blockquote:after,
  26. Q:before, Q:after {content: '; content:none;}
  27. a {margin:0; padding:0; font-size:100%; vertical-align:baseline; background:transparent;}
  28. INS {color: #000; text-decoration:none;}
  29. Mark {color: #000; font-style:italic; font-weight:bold;}
  30. del {Text-decoration:line-through;}
  31. Abbr[title], Dfn[title] {border-bottom:1px dotted #000; cursor:help;}
  32. /* Tables still need cellspacing= "0" in the markup * *
  33. Table {border-collapse:collapse; border-spacing:0;}
  34. hr {display:block; height:1px; border:0; border-top:1px solid #ccc; margin:1em 0; padding:0;}
  35. Input, select {Vertical-align:middle;}
  36. /* END RESET CSS */
Copy Code


2.
HTML5 Video with Flash Fallback
Explain the code, if the browser does not support HTML5 video playback, then will automatically jump back to flash playback.

    1. <video width= "640" height= "controls>"
    2. <source src= "__video__. MP4 "type=" Video/mp4 "/>
    3. <source src= "__video__. OGV "type=" Video/ogg "/>
    4. The <object width= "640" height= "type=", "Application/x-shockwave-flash" and "Data=" __flash__. SWF ">
    5. <param name= "movie" Value= "__flash__. SWF "/>
    6. <param name= "Flashvars" value= "controlbar=over&image=__poster__. jpg&file=__video__. MP4 "/>
    7. title= "No video playback capabilities, please download the video below"/>
    8. </object>
    9. </video>
Copy Code


3.HTML5 Starter Page

  1. <! DOCTYPE html>
  2. <meta charset = "Utf-8" >
  3. <title></title>
  4. <link rel= "stylesheet" href= "Style.css" >
  5. <script type= "Text/javascript" src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" ></ Script>
  6. <!--[if Ie]><script src= "Http://html5shiv.googlecode.com/svn/trunk/html5.js" ></script><! [endif]-->
  7. <script scr = "Script/script.js" ></script>
  8. <body>
  9. <nav>
  10. </nav>
  11. <footer>
  12. </footer>
  13. </body>
Copy Code


4. Create a Google static map

  1. <! DOCTYPE html>
  2. <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
  3. <meta name= "viewport" content= "Width=device-width, initial-scale=1.0 maximum-scale=1.0, User-scalable=no"/>
  4. <title>geo location</title>
  5. <style type= "text/css" media= "screen" >
  6. html{height:100%;}
  7. body{height:100%; margin:0; padding:0;}
  8. #map {width:100%; height:100%;}
  9. </style>
  10. <!--jQuery Min--
  11. <script type= "Text/javascript" charset= "Utf-8" src= "https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/ Jquery.min.js "></script>
  12. <!--Google Maps--
  13. <script type= "Text/javascript" charset= "Utf-8" src= "Http://maps.google.com/maps/api/js?sensor=true" ></ Script>
  14. <script charset= "Utf-8" type= "Text/javascript" >
  15. Mapwidth = Screen.width;
  16. Mapheight = Screen.height;
  17. $ (document). Ready (function () {
  18. var geo = navigator.geolocation;
  19. if (GEO) {
  20. Used for Static Maps
  21. Geo.watchposition (Showlocation, Maperror, {timeout:5000, enablehighaccuracy:true});
  22. }
  23. function Createstaticmarker (Markercolor, Markerlabel, lat, LNG) {
  24. Return "&markers=color:" + Markercolor + "|label:" + Markerlabel + "|" + Lat + "," + LNG;
  25. }
  26. function Createstaticmap (position) {
  27. var lat = position.coords.latitude;
  28. var lng = position.coords.longitude;
  29. var zoom = 20;
  30. var sensor = true;
  31. var img = $ ("
  32. Img.attr ({src: "Http://maps.google.com/maps/api/staticmap?" +
  33. "Center=" +
  34. Lat + "," +
  35. LNG +
  36. "&zoom=" + zoom +
  37. "&size=" + mapwidth + "X" + Mapheight +
  38. Createstaticmarker ("Blue", "1", lat, LNG) +
  39. "&sensor=" + sensor});
  40. return img;
  41. }
  42. function Showlocation (position) {
  43. var lat = position.coords.latitude;
  44. var lng = position.coords.longitude;
  45. var latlng = new Google.maps.LatLng (lat, LNG);
  46. $ ("#map"). html (createstaticmap (position))
  47. }
  48. function Maperror (e) {
  49. var error;
  50. Switch (e.code) {
  51. Case 1:
  52. Error = "Permission Denied";
  53. Break
  54. Case 2:
  55. Error = "Network or Satellites down";
  56. Break
  57. Case 3:
  58. Error = "Geolocation timed out";
  59. Break
  60. Case 0:
  61. Error = "Other error";
  62. Break
  63. }
  64. $ ("#map"). HTML (error);
  65. }
  66. });
  67. </script>
  68. <body>
  69. <div id= "Map" >
  70. </div>
  71. </body>
Copy Code


5. Pure HTML5 Starter Template

    1. <! DOCTYPE html>
    2. <meta charset= "Utf-8" >
    3. <title>Untitled</title>
    4. <!--[If Lt IE 9]>
    5. <script src= "Http://html5shim.googlecode.com/svn/trunk/html5.js" ></script>
    6. <! [endif]-->
    7. <body>
    8. </body>
Copy Code


6.HTML5 page Structure

  1. <! DOCTYPE html>
  2. <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
  3. <title>your website</title>
  4. <body>
  5. <nav>
  6. <ul>
  7. <li>your menu</li>
  8. </ul>
  9. </nav>
  10. <section>
  11. <article>
  12. <p>posted on <time datetime= "2009-09-04t16:31:24+02:00" >september 4th 2009</time> by <a href= "#" >Writer</a>-<a href= "#comments" >6 comments</a></p>
  13. <p>pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
  14. </article>
  15. <article>
  16. <p>posted on <time datetime= "2009-09-04t16:31:24+02:00" >september 4th 2009</time> by <a href= "#" >Writer</a>-<a href= "#comments" >6 comments</a></p>
  17. <p>pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
  18. </article>
  19. </section>
  20. <aside>
  21. <p>donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
  22. </aside>
  23. <footer>
  24. <p>copyright Your name</p>
  25. </footer>
  26. </body>
Copy Code


7. Context Menu

    1. <section contextmenu= "MyMenu" >
    2. <p>yes, this section right here</p>
    3. </section>
    4. <menu type= "Context" id= "MyMenu" >
    5. <menuitem label= "Please don't steal our images" icon= "Img/forbidden.png" ></menuitem>
    6. <menu label= "Social Networks" >
    7. <menuitem label= "Share on Facebook" onclick= "window.location.href = ' http://facebook.com/sharer/sharer.php?u= ' + Window.location.href; " > </menuitem>
    8. </menu>
    9. </menu>
Copy Code


8.HTML5 Datalist

    1. <input name= "Frameworks" list= "frameworks"/>
    2. <datalist id= "Frameworks" >
    3. <option value= "MooTools" >
    4. <option value= "Moobile" >
    5. <option value= "Dojo Toolkit" >
    6. <option value= "JQuery" >
    7. <option value= "YUI" >
    8. </datalist>
Copy Code


9. Get directions from Google Maps

    1. <form action= "Http://maps.google.com/maps" method= "get" target= "_blank" >
    2. <label for= "Saddr" >enter your location</label>
    3. <input type= "text" name= "Saddr"/>
    4. <input type= "hidden" name= "Daddr" value= "5th Ave New York, NY 10018 (Empire State Building)"/>
    5. <input type= "Submit" value= "Get directions"/>
    6. </form>
Copy Code


10.HTML5 e-mail Regular expression validation

    1. <input type= "text" title= "email" required pattern= "[^@][email protected][^@]+\. [A-za-z] {2,6} "/>
Copy Code

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.