分享10段實用的HTML5程式碼
隨著HTML5的流行,許多網站開始介紹HTML5元素和屬性的用法,以及各種教程,並且越來越多老的瀏覽器開始相容HTML5。
本文作者編譯了10段非常實用的HTML5程式碼片段,開發者可以直接拿過去使用,幫你快速完成HTML5專案的開發工作,你也可以把它們當做一個學習資源,進行參考。
CSS Reset也可以寫成Reset CSS,即重設瀏覽器樣式。
/* 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/*/ html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, figure, footer, header, hgroup, menu, nav, section, menu, time, mark, audio, video { margin:0; padding:0; border:0; outline:0; font-size:100%; vertical-align:baseline; background:transparent; } article, aside, figure, footer, header, hgroup, nav, section { display:block; } nav ul { list-style:none; } blockquote, q { quotes:none; } blockquote:before, blockquote:after, q:before, q:after { content:''; content:none; } a { margin:0; padding:0; font-size:100%; vertical-align:baseline; background:transparent; } ins { background-color:#ff9; color:#000; text-decoration:none; } mark { background-color:#ff9; color:#000; font-style:italic; font-weight:bold; } del { text-decoration: line-through; } abbr[title], dfn[title] { border-bottom:1px dotted #000; cursor:help; } /* tables still need cellspacing="0" in the markup */ table { border-collapse:collapse; border-spacing:0; } hr { display:block; height:1px; border:0; border-top:1px solid #ccc; margin:1em 0; padding:0; } input, select { vertical-align:middle; } /* END RESET CSS */
2.HTML5 Video with Flash Fallback
解釋下該段程式碼,如果瀏覽器不支援HTML5視訊播放,那麼會自動跳回Flash播放。
<video width="640" height="360" controls> <source src="__VIDEO__.MP4" type="video/mp4" /> <source src="__VIDEO__.OGV" type="video/ogg" /> <object width="640" height="360" type="application/x-shockwave-flash" data="__FLASH__.SWF"> <param name="movie" value="__FLASH__.SWF" /> <param name="flashvars" value="controlbar=over&image=__POSTER__.JPG&file=__VIDEO__.MP4" /> <img src="__VIDEO__.JPG" width="640" height="360" alt="__TITLE__" title="No video playback capabilities, please download the video below" /> </object> </video>
<!DOCTYPE HTML> <html> <head> <meta charset = "utf-8"> <title></title> <link rel="stylesheet" href="style.css"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--> <script scr ="script/script.js"></script> </head> <body> <header> <nav> </nav> </header> <footer> </footer> </body> <html>
4.建立谷歌靜態地圖
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=1.0, user-scalable=no" /> <title>Geo Location</title> <style type="text/css" media="screen"> html{ height: 100%; } body{ height: 100%; margin: 0; padding: 0; } #map{ width: 100%; height: 100%; } </style> <!-- jQuery Min --> <script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <!-- Google Maps --> <script type="text/javascript" charset="utf-8" src="http://maps.google.com/maps/api/js?sensor=true"></script> <script charset="utf-8" type="text/javascript"> mapWidth = screen.width; mapHeight = screen.height; $(document).ready(function(){ var geo = navigator.geolocation; if( geo ){ //Used for Static Maps geo.watchPosition( showLocation, mapError, { timeout: 5000, enableHighAccuracy: true } ); } function createStaticMarker( markerColor, markerLabel, lat, lng ){ return "&markers=color:" + markerColor + "|label:" + markerLabel + "|" + lat + "," + lng; } function createStaticMap( position ){ var lat = position.coords.latitude; var lng = position.coords.longitude; var zoom = 20; var sensor = true; var img = $("<img>"); img.attr( { src: "http://maps.google.com/maps/api/staticmap?" + "center=" + lat + "," + lng + "&zoom=" + zoom + "&size=" + mapWidth + "x" + mapHeight + createStaticMarker( "blue", "1", lat, lng ) + "&sensor=" + sensor } ); return img; } function showLocation( position ){ var lat = position.coords.latitude; var lng = position.coords.longitude; var latlng = new google.maps.LatLng( lat, lng ); $("#map").html( createStaticMap( position ) ) } function mapError( e ){ var error; switch( e.code ){ case 1: error = "Permission Denied"; break; case 2: error = "Network or Satellites Down"; break; case 3: error = "GeoLocation timed out"; break; case 0: error = "Other Error"; break; } $("#map").html( error ); } }); </script> </head> <body> <div id="map"> </div> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Untitled</title> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> </body> </html>
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Your Website</title> </head> <body> <header> <nav> <ul> <li>Your menu</li> </ul> </nav> </header> <section> <article> <header> <h2>Article title</h2> <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> </header> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p> </article> <article> <header> <h2>Article title</h2> <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> </header> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p> </article> </section> <aside> <h2>About section</h2> <p>Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> </aside> <footer> <p>Copyright 2009 Your name</p> </footer> </body> </html>
7.上下文選單
<section contextmenu="mymenu"> <p>Yes, this section right here</p> </section> <menu type="context" id="mymenu"> <menuitem label="Please do not steal our images" icon="img/forbidden.png"></menuitem> <menu label="Social Networks"> <menuitem label="Share on Facebook" onclick="window.location.href = 'http://facebook.com/sharer/sharer.php?u=' + window.location.href;"> </menuitem> </menu> </menu>
<input name="frameworks" list="frameworks" /> <datalist id="frameworks"> <option value="MooTools"> <option value="Moobile"> <option value="Dojo Toolkit"> <option value="jQuery"> <option value="YUI"> </datalist>
<form action="http://maps.google.com/maps" method="get" target="_blank"> <label for="saddr">Enter your location</label> <input type="text" name="saddr" /> <input type="hidden" name="daddr" value="350 5th Ave New York, NY 10018 (Empire State Building)" /> <input type="submit" value="Get directions" /> </form>
<input type="text" title="email" required pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}" />
來自: CodeGeekz
相關文章
- 馬哥分享的25段shell指令碼程式碼,日常工作基本夠用指令碼
- 50個必備的實用jQuery程式碼段jQuery
- 經驗分享:10個簡單實用的jQuery程式碼片段jQuery
- 分享一段牛逼程式碼
- Web開發者的福利 30段超實用CSS程式碼WebCSS
- 10款很酷的HTML5動畫和實用應用 有原始碼HTML動畫原始碼
- 即學即用的 30 段 Python 非常實用的程式碼Python
- 10個典型實用的PHP程式碼片段PHP
- WIN10UI—實現思路分享及程式碼Win10UI
- 分享一段Android許可權設定的程式碼Android
- HashTable實現程式碼分享
- 10個簡單實用的 jQuery 程式碼片段jQuery
- 分享兩個實用的shell指令碼指令碼
- 用7段程式碼來理解常用的寫作模式模式
- Jquery實現的高亮效果程式碼分享jQuery
- 分享幾個工作中實用的程式碼最佳化技巧!
- 精選HTML5/CSS3動畫應用原始碼分享HTMLCSSS3動畫原始碼
- 10個經典實用的HTML5圖表動畫應用HTML動畫
- 10款絢麗實用的HTML5圖表動畫應用HTML動畫
- 10個開發中實用的 jQuery 程式碼片段jQuery
- 前端必會的程式碼段前端
- 10款效果驚豔的HTML5應用和原始碼HTML原始碼
- 分享實用監控指令碼:使用Shell檢查程式是否存在指令碼
- 用三段140字元以內的程式碼生成一張1024×1024的圖片字元
- Python實現裝飾模式的一段程式碼Python模式
- iOS 程式碼段收集iOS
- javascript常用程式碼段JavaScript
- JS HOOK 程式碼段JSHook
- C# 程式開發中經常遇到的10條實用的程式碼C#
- C#程式開發中經常遇到的10條實用的程式碼C#
- 用php編寫我的第一段程式碼:hello worldPHP
- 移動網站開發中常用的10段JavaScript程式碼網站JavaScript
- 利用html5實現的飛雪效果程式碼例項HTML
- HTML5 實現的音樂播放器分享HTML播放器
- 分享一段處理多維陣列,unidecode的中文的字元的程式碼陣列IDE字元
- 【趣圖】這段程式碼看起來沒用,刪了吧....
- 限時10分鐘,你會怎麼實現這段async/await程式碼?AI
- 淺談c語言程式碼段 資料段 bss段C語言