|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
一些公司联合起来,成立了一个叫做WebHypertextApplicationTechnologyWorkingGroup(Web超文本应用技术工作组-WHATWG)的组织。网页制造poluoluo文章简介:在这篇文章中,我但愿可以给你一些提醒和洞察HTML5,以匡助加重痛苦悲伤的一定附带过渡到一种略有分歧的语法。
有些人承受了,有些人抛弃它太悠远的将来,有些人保持了滥用的伴侣有益于旧火焰在准备。任何一方的争吵你的,你最有大概听到的一切的博客谈天环绕“新酷热”,也就是HTML5。它无处不在,它的将来,和你想晓得的统统,您能够收到的旧旧事。
像jQuery插件,格局手艺,并计划趋向的变更十分敏捷地在全部收集社会。并在年夜多半情形下我们都承受的是,有些事变我们晓得明天能够过期的今天,可是这是我们行业的性子。
在寻觅一些不乱,我们一般能够转向代码自己,由于它常常会坚持稳定了很长一段工夫(绝对而言)。因而,当一些欣喜和改动我们的代码,这是一个年夜成绩,和将有一些发展的疾苦,我们必需经由过程。侥幸的是,据传,我们已少了一个变更的忧虑。
在这篇文章中,我但愿可以给你一些提醒和洞察HTML5,以匡助加重痛苦悲伤的一定附带过渡到一种略有分歧的语法。
WelcometoHTML5.
Whatarethebasics?
TheDOCTYPE
WhenIfirststartedresearchingHTML5afewmonthsago,oneofthemainthingsIstruggledtofindwasthedoctype.Asimplething,you’dthinkitwouldbeeverywhere,butaftermuchfrustration,Ifinallyfounditburiedwithinw3.organdhereitis:我也猎奇,为何他们选择“的HTML”,而不是“html5”,这仿佛符合逻辑的体例来告知扫瞄器,今朝的文件写于HTML5,并供应了一个优秀的范本,以供将来。但我发明,<!DOCTYPEhtml5>触发夸克斯形式中的IE6,和向后兼容时,思索到<!DOCTYPEhtml>是一个相称不错的选择(在我看来)。
总之,我真的很喜好这个新的文档,它的小的,成心义的,大概我们会实践上可以记着这个时候的心,而不是将其粘贴在网站上。
NewElementsyoushouldknow
Atfirstglance,withHTML5,thenewelementsimmediatelyjumpoutandcommandattention.TheW3Creallylistenedtothecommunityandplannedforthefuturewhenarchitectingtheabundanceofnewelementsavailable.Wehaveeverythingfrombasicstructuralelementslike<header>and<footer>tootherslike<canvas>and<audio>thattapinto,whatseemstobe,averypowerfulAPIwhichallowsusthefreedomtocreatemoreuser-friendlyapplicationswhilefurtherdistancingourselvesfromrelianceonFlashforsavingdataandintenseanimation.
Thenewstructuralelements
- <header>
Theheaderelementcontainsintroductoryinformationtoasectionorpage.Thiscaninvolveanythingfromournormaldocumentsheaders(brandinginformation)toanentiretableofcontents.
- <nav>
Thenavelementisreservedforasectionofadocumentthatcontainslinkstootherpagesorlinkstosectionsofthesamepage.Notalllinkgroupsneedtobecontainedwithinthe<nav>element,justprimarynavigation.
- <section>
Thesectionelementrepresentsagenericdocumentorapplicationsection.Itactsmuchthesamewaya<div>doesbyseparatingoffaportionofthedocument.
- <article>
Thearticleelementrepresentsaportionofapagewhichcanstandalonesuchas:ablogpost,aforumentry,usersubmittedcommentsoranyindependentitemofcontent.
- <aside>
Aside,representscontentrelatedtothemainareaofthedocument.Thisisusuallyexpressedinsidebarsthatcontainelementslikerelatedposts,tagclouds,etc.Theycanalsobeusedforpullquotes.
- <footer>
Thefooterelementisformarkingupthefooterof,notonlythecurrentpage,buteachsectioncontainedinthepage.So,it’sverylikelythatyou’llbeusingthe<footer>elementmultipletimeswithinonepage.
Whenyoutakealookatthesenewelements,itlookslikethey’rejustreplacingourcommonDIVIDs;andinaway,it’strue.But,thediagrambelowshowsthatelementslike<header>and<footer>canbeusedmorethanonceonasinglepagewheretheybehavemorelikeclassesandnormalHTMLelementsthatyoucanuseoverandoveragaintoretainasemanticstructure.
Elementslike<header>and<footer>arenotjustmeanttorepresentthetopandbottomofthecurrentdocument,buttheyalsorepresentthe<header>and<footer>ofeachdocumentsection,muchthewayweuse<thead>and<tfoot>indatatables.
Thebenefitsofusingthesestructuralelementsismainlyduetothefactthattheyareextremelywelldefinedandprovideagreatwaytosemanticallystructureyourdocument.However,theseelementsdoneedtobeusedwithsomecarefulthoughtbecausetheycan,veryeasilybeoverused.
FurtherReadingonstructuralHTML5
- SteveSmithonStructuralTagsinHTML5
- LachlanHunt’sPreviewofHTML5
- ElliotHaroldonNewElementsinHTML5
- BruceLawson’sHTML5FormDemo
EasingthetransitionfromXHTML
EventhoughHTML4.01,XHTML1.0,&HTML5areallverysimilartherearesomesmallsyntaxdifferencesthatcan,veryeasily,slippastanyoneandinvalidatecode.Keepingthisinmind,HTML5hassomebuilt-in“slack”tomakethetransitionalittleeasier.
Forexample,whenmarkingupaforminHTML5,thisisthepropersyntaxforaninputtextelement:- <inputtype="text"id="name">
复制代码 ButthisisalsoacceptedasvalidcodeinanattempttoeasethepainforavidXHTMLcoders(likemyself)whoareusedtoself-closingelements:- <inputtype="text"id="name"/>
复制代码 Thesamerulesapplyto<meta>andotherselfclosingelements.Legacyelementslike<b>and<i>werealsoleftintohelpthosecomingoverfromHTML4.01.l
Whatarethebenefits?
Withanynewtechnologytherehastobebenefit;whyelsewouldyouuseit?Ifyouroldcodeworksjustaswellandefficientasthenewcodethere’snoreasontoupgrade.Noreasonatall,trustme,Ichecked.
LuckilyHTML5ispackedwithcoolnewfeatures,codeslimmingtechniquesandalotofstuffIwouldcallverylargebenefits.MostofwhichcirclearoundthenewAPIsandtheDOMtree.
网页制造poluoluo文章简介:在这篇文章中,我但愿可以给你一些提醒和洞察HTML5,以匡助加重痛苦悲伤的一定附带过渡到一种略有分歧的语法。
ExtendingtheAPI
ThemostobviousbenefitbuiltintoHTML5isthenumerousAPIsandtheopportunitiesitopensupforthefutureofwebappswithHolyGrailofapplicationcacheandofflinecapabilities.GoogleGearsgaveusofflinedatastorageandFlashintroducedustothepowerofapplicationcache(Pandorausesittosaveyourlogininformation).WithHTML5,thesecapabilitiesarenowavailabletouserightinthelanguageandcaneasilybeexpandedwithJavaScript.
HTML5reliesonlightscriptingtoflexitsmusclesontheWeb;thisisverypossiblythefirsttime,otherthanjQuery,thatone(front-end)technologyhasfullyacknowledgedanother.Sure,weconnectthemwithclassesandIDsbutupuntilnow,theyhavebeenperceivedasseparatelayersbytheprinciplesofprogressiveenhancement.ButastheWebgrowsweneedunitylikethisacrosstheWeb.
OfflineDataStorage
ThecoolestpartaboutHTML5isdefinitelyitsofflinecapabilities.ProgramslikeThunderbirdandOutlook(andnowGMailtoanextent)letyoubrowsethroughyourolddatawhilestayingoffline.WithHTML5,you’llhavethissamefunctionality,butinthebrowser.ThisisthefirstserioussteptowardsbridgingthegapbetweenthedesktopandtheWeb,andopensallsortsofdoorsforthefutureofWebapps.
TheW3ChastakenthebestpartsfromthevariousWebtechnologiesandrolledtheminto,whatisbeingdubbedthemostpowerfulmarkuplanguagetodate.
SomeotheroftheHTML5APIs
- Drag&Drop
ThedraganddropAPIdefinesanevent-baseddraganddropsystem.However,itneverdefineswhat“draganddrop”is.ThisAPIrequiresJavaScripttofullyworkasnormalthinkdraganddropfunctionality.
- Video&Audio
Theaudio&videoAPIsaremassiveupgradesinmediaembedding.Althoughsupportislimitedrightnow,somethinglikevideoembeddinghasneverbeeneasier:- <videowidth="400"height="360"src="vid.mp4">
复制代码 - Geolocation
GeolocationisaverycoolAPIavailablewithinHTML5.Itsobjectcanbeusedtoprogrammaticallydeterminelocationinformationthroughadevice’suseragent(hinthint:mobiledevices).
FurtherreadingontheHTML5API
- OfflineWebApplications
- OfflineApplicationCaching
- RemySharponJavaScriptAPIsHTML5(presentation)
- O3DBeachDemofromGoogle(musthaveanHTML5capablebrowser)
WherecanIuseit?
EvenwiththeverylimitedsupportforHTML5,theWebisfartooprogressivetonotcreateatestingenvironmentforustoplayaround.Currently,Safariisourbesttestingplatform,asitsupportsmostofthenewelementsandAPIs.Ofcourse,thatmaychangeatanytimesokeepandeyeonOpera,ChromeandFirefoxaswell.
NormallyyoumightthinksinceSafariisaWebkitbrowser,bydefault,allWebkitbrowserswouldsupportthesameelements,unfortunately,thisisn’tthecase.WhilemanyoftheHTML5featuresaresupportedacrosstheboardinWebkitbrowsers,therearesome,like<video>,thatarenot.
Mobiledevices
ToeffectivelyuseHTML5rightnow,weneedtobeabletocontroltheenvironmentinwhichitisused.Sincesupportisnotaswidespreadaswe’dlikeitdoesn’tmakerealsenseforittobeheavilyusedunless,ofcourse,wecanlockdowntheusagetocertainplatformswhichhaveHTML5support.WithWebkitleadingthewayforHTML5,wecansafelyfocusondevicespoweredbyWebkit.
The3hottestmobiledevicesrightnow:ThePalmPre,iPhone3GsandthenewGoogleAndroidphoneallhavebrowsersthatarebasedofftheWebkitrenderingengine.
SafariisevenleadingthewayonthemobileHTML5front;TheiPhone(withthelatestsoftwareupgrade)istheonlydeviceIcouldgettoproperlyrenderthe<audio>element.Becausethesedevicesaresoyoungandallusethesamerenderingengine,thelikelihoodofthempushingarapidsoftwareupgradeisprettyhigh.
Rightnow,youcanconfidentlyusemanyoftheHTML5featuresiniPhoneWebappdevelopmentandmostlylikelyexpectPreandAndroidtofollowinsuit.
FurtherreadingonwhereyoucanuseHTML5
- HTML5FeaturesinlatestiPhone
- GMailWebappfortheiPhone
- GMailforHTML5
- SupportedFeaturesinHTML5
- HTML5CheatSheet
Howcanwemoveforward?
EvenwithalltherecenthypesurroundingHTML5andhowweallwanttouseit,itisstillgoingtobeaveryslowtransitionawayfromHTML4.01&XHTML1.0.Itwilltaketimetogetdevelopersuptospeed,testallthefeatures,waitingforallthe:ahem:browserstocatchup,anditwilltakeanespeciallylongtimeforuserstotransitionoutofthoseoldbrowsers.Withallthatinmind,weknowwhoweare,we’reallreadingthisarticle(I’vereaditabout30timessofar)andweknowwehavetofindalegitimatewaytomoveforwardwithoutdamagingthepast.
Wecan’tmakethefullswitchyetandthere’snouseatthispointpointingoutwhoisholdinguptheshow.Weallknowthatanyresponsibledeveloperwouldnotdropsupportforabrowserthatisstillheavilyused.Soratherthanyellatabrickwall,herearesomethingsI’vefoundthatmighthelpusmoveforwardinapositiveway:
SemanticDIVnaming
SemanticallyaligningyourDIVnameswiththatofthenewHTML5elementswillhelpyougetusedtothenamesthemselvesandalsothenewfunctionalityandnestingthattheywantyoutodowiththe<header>and<footer>elements.TheseareakintolearningtheintrotheEnterSandman(fortheguitaristoutthere);it’snotverydifficult,butittakesalittlepracticetogetittofeelnatural.
Beforejumpinginfull-forcetoHTML5productionsites,IrecommendtryingthesofttransitionwithchangingyourDIVnamesslightly.There’snodownsidethatI’vefoundtodoingthis,youcanevenusethenewDOCTYPEwithverylittleconsequence.
FakingitwithJavaScript
Firstoff,I’dliketosay:Pleasedon’tdothisinproduction.Iftheclientsidescriptingfails,itwillcompletelycollapsethesiteinbrowsersthatwon’ttakeCSSappliedtothenewelements.Thisissimplynotagoodoption.Itis,however,anoptionandI’mallaboutknowingyouroptionsnomatterwhattheyare.
CreatingthenewelementswithJavaScript
WorkinginjQueryiscoolandall,butasitturnsout,thereisabuiltinfunctiontoJavaScripttodealwithcreatingnewelements:- document.createElement(header);document.createElement(footer);document.createElement(section);document.createElement(aside);document.createElement(nav);document.createElement(article);document.createElement(figure);document.createElement(time);
复制代码 …andsooninthatfashion.
ThiswillallowyoutostyletheseelementsinInternetExplorer.Again,thedownsideofusingthistechniqueisthat,withouttheall-importantJavaScript,thesitewillnotonlybeunstyled,alltheunrecognizedelementswilldefaulttoinline.Soyoursitewillliterallycollapseonitself.
ClientsideJavaScriptisnottheanswerforusingHTML5.Serversidejavascript,nowthat’sacompletelydifferentstory…
网页制造poluoluo文章简介:在这篇文章中,我但愿可以给你一些提醒和洞察HTML5,以匡助加重痛苦悲伤的一定附带过渡到一种略有分歧的语法。
Buildingbrowser-specificapps
I’vealwayspromotedbuildingsitesforyouraudience,sodependingonyouraudience,buildingbrowser-specificapplicationsmaybearealoption.AsImentionedabove,it’sallaboutcontrollingtheenvironment,ifwecancontroltheenvironmentwecancontrolfeaturesdeliveredtotheusermuchbetter.GoogleiscurrentlyattemptingtodothiswithGoogleWave.
TheideabehindGoogle’snewmonsterproductistorevolutionizecommunication,anddosowiththenewesttechnology.GoogleWaveisbuiltinHTML5andisn’tusableinallbrowsersyet.Butthat’salrightsincethey’recontrollingtheaudiencebyonlyreleasingittoselectdevelopersfortesting.
WithWave,GoogleispushingHTML5asfarasitwillgo(andevenalittlefurther).Theyaretakingblogs,wikis,instantmessaging,e-mailandsynchronouscommunicationtothenextlevelbycombiningthemintoplace.
HereiswhattheWaveinboxlookslike.
Belowisasortofwiki/chatareawithallsortsofreal-timecommunicationtreatsforyoutocheckout(oncetheyreleaseit).
GoogleWavebeingpoweredbyHTML5isdefinitelythebiggeststepforwardwehaveseeninthisarea.Theyhavedoneaphenomenaljobputtingtogetheracreativeandinnovativeproduct.
Focusingonthemobile
JustlikeGoogleiscurrentlydoingwithWavebyselectivelyreleasingittodevelopers,wecancontroltheviewingenvironmentwhenworkingwithmobiledevices.Bygrabbingtheuseragent,wecandesignspecificapplicationsthatuseHTML5forsupporteddevices.
Targetingtheuseragentofadeviceisnotanidealmethodindesigningforthegeneralmobileweb,butwhenweneedtospecificallytargetadevice,liketheiPhone,PreorGoogle’sAndroidit’saprettysolidoption.
Rightnow,thebestmobiletestingplatformwehaveistheiPhone.Withtherecentsoftwareupgrade,itisveryclosetohavingfullsupport.But,ifyoujustwanttousethenewelements,mostanyofthebig3mobileplatformswillworkfine.Ifyou’relookingforAPIsupportIsuggesttestingontheiPhonewiththenewupgradedsoftware.
Conclusion
Withthestrongfoundationssetupbypreviousversionsof(X)HTMLandlargecommunityactivitysurroundingWebstandards,we’recomingintoanewagewithawealthofknowledgeandtheabilitytolearnfromourpastmistakes(andmakesomenewones).HTML5isbeingsetupwiththeexpectationsofaverypowerfulmarkuplanguageandit’suptoustoutilizeitinawaythatcanbenefitusall.
TherearesomanygreatfeaturestolookforwardtofromnewelementstotonsofkillerAPIs.Wecanmakedataavailableoffline,easilycombinetechnologiesandcreateveryintricateanimationsallwithinafamiliarlandscape.Ifyouhavethetime,Iencourageyoutobrowsethroughtheentirespecandfamiliarizeyourselfevenfurtherwithallthebellsandwhistles(therearealot)sowecanuseHTML5tobuildstronger,richerWebapplicationsforyearstocome.
Here’stoHTML5,let’shopeitlivesuptothehype.
Resources
- 23EssentialHTML5Resources
AcomprehensivelistofarticlesandresourcesrelatedtoHTML5.
- HTML5Demos
HTML5DemosisagreatresourceforcheckingouttheHTML5APIssuchas:geolocation,draganddrop,offlinedetection,andstorage.ThisisaverygoodanduniqueresourcestotestoutandseeexactlywithwecandowithHTML5.
- HTML5Gallery
TheHTML5Gallery,likeanygallery,isawebsiteshowcasewhereyoucanseehowothersareusingHTML5ineverydaydevelopment.I’velookedroundthoughthissitequiteabitanddidsomecrossbrowsertestingonsomeoftheentries.Manyarebrokeninolderbrowsers,buttherearesomethatholdupverywell.
- HTML5Doctor
AresourcethatcateredforthepeoplewhowishedtofindoutmoreaboutimplementingHTML5andhowtogoaboutit.ThisblogpublishesarticlesrelatingtoHTML5andit’ssemanticsandhowtousethem,hereandnow.
- HTML5CheatSheet
AhandyprintableHTML5CheatSheetthatlistsallcurrentlysupportedtags,theirdescriptions,theirattributesandtheirsupportinHTML4.Releasedhere,atSmashingMagazine.
- W3CHTML5SpecOverview
Wheneveryouwanttoknow
aboutsomethingthatnoonehaswrittenaboutontheWeb,theW3Cisyouranswer.IspenthoursscouringthissiteinresearchingHTML5.It’sagreatresourceandIhighlyrecommendreadingthroughwhateveryoucan.
- HTML5Validator
Evenwithsuchlittlesupport,westillwanttomakesureourcodeisvalid.ValidatingyourcodeisagreatwaytolearnandeaseyourselfintodevelopingwithHTML5.
- WHATWGWiki
TheHTMLWorkingGrouphasputtogethersomegreatdocumentationfortrackingwhatexactlyisgoingonintheworldofHTML5.
References
- Yes,YouCanUseHTML5Today!
- W3CHTML5Differences
- 5AmazingHTML5FeaturestoLookForwardto
- PreviewofHTML5
- PreparingforHTML5withSemanticClassNames
- XHTML2vs.HTML5
- HTML4vs.HTML5
- AccessibilityinHTML5
- HTML5Doctor
</p>
最近群里面很多人在问html5应该怎么学,这个问题其实没有标准答案。我开这个帖子,目的是为了收集大家每天的学习心得,欢迎大家来回复。 |
|