来自 热门技术 2018-09-12 10:38 的文章

英文教程:五种CSS选择器类型

英文教程:五种CSS选择器类型. CSScommandsareusuallygroupedinthecurlybracestomakeasetofrules.FollowingarethevariouswaysavailabletoattachthesesetofruleswithHTMLcode.Selector(in******words)meanshowyounamethesesetofrules.1CLASSSelectORSClassselectorsisthe******stformofselectorswhereyouassignyourownmeaningfulnametothesetofCSSrules.Tocreateaclassselectoryousimplyneedtowritenameoftheclassfollowedbyaperiod.(Aclassnamecannotstartwithanumberorasymbolasitisnotsupportedbyvariousbrowsers.)Forexample, p.big{font-weight:bold;font-size:12px;}.center{text-align:center;} AndthisHTML: <pclass="big">Thisparagraphwillberenderedbold.www.jb51.net</p> Youcanapplymorethanoneclasstoagivenelement.AndthisHTML: <pclass="centerbig">Thisparagraphwillberenderedbold.</p> Intheaboveexample.bigand.centerarenameofCSSclassesandtheseclassesareappliedtoPtaginHTML.IfclassnameisfollowedbyHTMLelementinyourCSScodelikep.biginaboveexampleitmeansthatthisclasswillworkonPtagonly.OtherwiseyoucanapplytheCSSclassonanyelement.It’sagoodpracticetoaddHTMLelementbeforeclassnameinCSSifyouarewritingCSSrulesforaparticularelement(ItaddsmoreclaritytoCSScode.2IDSelectORSIDselectorsworklikeclassselector****ceptthattheycanonlybeusedononeelementperpagebecausetheyworkwithIDofthehtmlelement.TheidselectorisdefinedasidoftheHTMLelementfollowedbya#symbol.Forexample, p#navigation{width:12em;color:#666;font-weight:bold;} AndthisHTML: <pid="navigation">Thisparagraphwillberenderedbold.www.jb51.net</p> AsagoodpracticeIDselectorsmustbeusedifyouarewritingtheCSScodeforasingleHTMLelementonly.IDselectorsarewellsupportedacrossstandards-compliantbrowsers.3TAGSelectORTagselectorisanother******methodofCSSrule******mentation.YoucanusethisselectortoredefinetherulesforaparticularHTMLelement.Forexample: p{color:#999;font-weight:bold;} IntheaboveexampleCSScodewillbeautomaticallyappliedoneveryptag.4DESCENDENTSelectORSDescendentselectorsspecifythatstylesshouldonlybeappliedwhentheelementinquestionisadescendent(forexample,achild,oragrandchild)ofanotherelement.Forexample, h3em{color:white;background-color:black;} AndthisHTML: <h3>Thisis<em>emphasized</em>www.jb51.net</h3> Intheaboveexampleemisdescendentofh3element.Abovecssrulewillautomaticallybeappliedonallemelementsinsideh3elementintheHTMLcode.Descendentselectorsarewellsupportedacrossstandards-compliantbrowsers.5GROUPINGSelectORSYoucanalsospecifythesamesetofrulesformorethanoneselctor,likethis: p,h1,h2{text-align:left;} Justplaceacommabetweeneachone.Youcanevengetmorecomplex,andgroupmul***leclassandidselectors: p.navigation,h1#title{font-weight:bold;}

本文源自: AG88平台