Html5 代码
随着HTML5的流行,许多网站开始介绍HTML5元素和属性的用法,以及各种教程,并且越来越多老的浏览器开始兼容HTML5。
本文作者编译了10段非常实用的HTML5代码片段,开发者可以直接拿过去使用,帮你快速完成HTML5项目的开发工作,你也可以把它们当做一个学习资源,进行参考。
CSS Reset也可以写成Reset CSS,即重设浏览器样式。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
/* 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, h 1 , h 2 , h 3 , h 4 , h 5 , h 6 , 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播放。
1
2
3
4
5
6
7
8
9
10
|
< 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 > |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<!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.创建谷歌静态地图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<!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 > |
1
2
3
4
5
6
7
8
9
10
11
12
|
<!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 > |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<!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.上下文菜单
1
2
3
4
5
6
7
8
9
|
< 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 > |
1
2
3
4
5
6
7
8
|
< 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 > |
1
2
3
4
5
6
|
< 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 > |
1
|
< input type = "text" title = "email" required pattern = "[^@]+@[^@]+\.[a-zA-Z]{2,6}" /> |
Html5 代码的更多相关文章
- html5代码,获取地理位置
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <meta htt ...
- 获取地理位置的html5代码
/** * 以下为html5代码,获取地理位置 */ function getLocation() { //检查浏览器是否支持地理位置获取 if (navigator.geolocation) { / ...
- 极客无极限 一行HTML5代码引发的创意大爆炸
摘要:一行HTML5代码能做什么?国外开发者Jose Jesus Perez Aguinaga写了一行HTML5代码的文本编辑器.这件事在分享到Code Wall.Hacker News之后,引起了众 ...
- HTML5代码规范
HTML5代码规范html标签里面等号两边不要留空格在IE下可能会识别不了html5等号前后可以使用空格,但仍不推荐使用. HTML 代码约定很多 Web 开发人员对 HTML 的代码规范知之甚少.在 ...
- 在网站制作中随时可用的10个 HTML5 代码片段
HTML 很容易写,但创建网页时,您经常需要重复做同样的任务,如创建表单.在这篇文章中,我收集了10个超有用的 HTML 代码片段,有 HTML5 启动模板.空白图片.打电话和发短信.自动完成等等,帮 ...
- 关于HTML5代码总结。
在阅读完HTML5后,自己把一些常用的代码总结了一下,自认为比较全,如果有什么错误请指出. 1.<!DOCTYPE html>声明这是一个HTML5的页面 2.<HTML lang= ...
- 绝对应当收藏的10个实用HTML5代码片段(转)
HTML5绝对是一个流行元素,受到如此多的公司组织的追捧,作为极客来说,岂能错过呢?在今天这篇文章中,我们将分享一些超实用的HTML5的代码片段,相信大家一定会喜欢! 正确的嵌入flash 如果你经常 ...
- 10段实用的HTML5代码
1.HTML5编写的CSS ResetCSS Reset也可以写成Reset CSS,即重设浏览器样式. /* html5doctor.com Reset Stylesheet (Eric Mey ...
- !!常用HTML5代码
HTML5提供的新特性 2016-2-16 Web Socket 定义了一套API, 允许网页能够使用Web Socket协议来和远程主机进行双工通信. Web Storage 定义了一套API, 能 ...
随机推荐
- 网络爬虫(3)--Beautiful页面解析
前面2节中对页面内容的访问都是直接通过标签访问的,这样虽然也可以达到解析页面内容的目的,但是在网页复杂,页面结构发生变化时,爬虫就失效了.为了使爬虫能够更加鲁棒的工作,我们需要学习通过 ...
- gdalwarp:变形工具
1 gdalwarp:变形工具.包括投影.拼接.及相关的变形功能.此工具功能强大,但效率不高,使用时注意 gdalwarp [--help-general] [--formats] [-s_s ...
- Func 委托 和 Action 委托 初步谈论
继上篇EventHandler之后,继续填坑,简单了解下Func<TResult> 委托 和 Action 委托. msdn对于两者的解释: Func<TResult>:封装一 ...
- 利用IIS7 解决URL访问限制问题
网站可以通过URl直接访问一些不希望被访问的东西, 比如一些图片,js,css等等. 为了解决这个问题看了好多文章,不过毕竟我是新手菜鸟级别的,没有具体的解决方法,真心不知道怎么弄. 今天在看IIS的 ...
- DataList、Repeater、GridView中的Checkbox取值问题
先看页面代码 <asp:DataList id="DataList1" runat="server" Width="100%" Rep ...
- TextField详细用法
http://www.cnblogs.com/VincentXue/archive/2012/08/28/2660001.html
- [poj2762] Going from u to v or from v to u?(Kosaraju缩点+拓排)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Going from u to v or from v to u? Tim ...
- java中的IO流读取文件
1 InputStream类和OutputStream类 InputStream.read()方法从文件中读取一个字节(0-255),然后将此字节转换成对应的整数返回.假设一个文件的编码为utf-8编 ...
- Centos安装php提示virtual memory exhausted: Cannot allocate memory
由于内存不够,需要在php配置的时候./configure最后添加上 --disable-fileinfo >>./configure --prefix= ........... -- ...
- PHP获取客户端操作系统,浏览器,语言,IP,IP归属地等
<?php class Client { ////获得访客浏览器类型 function Get_Browser(){ if(!empty($_SERVER['HTTP_USER_AGENT']) ...