I justhave a reallysimpleHTMLdocumentwithan H oneand a P tag, andthis H onehas a classofheaderandthis P taghas a classoftext.
Andthenwehave a verysimplestyleschangeintheheaderto a colorofredandthetextto a colorofgreen.
Andasyoucanseeoverhere, we'regettinganoutputof a redhead.
Erandgreenbodytext.
Andthisisallgreat.
Thisallmakessense.
Andsomethingelsethatyou'realmostcertainlyfamiliarwithisthatifwehadtheexactsameselectortwiceinsideofourCSSandthebottomonegave a colorblueinthetoponegave a colorofred.
Asyoucansee, wehaveheader I d downheresowecanselectthatheader I d Andwecanchangethecolortobe, forexample, black.
Andnowifwesaythatyoucanseeourcolorisnowblackandthat's because I d.
S areevenmorespecificthanclasses.
AndthewaythatCSSusesthisspecificitytodeterminehowinelementsactuallyselectedisittakes a combinationofallthedifferenttypesofspecificityandthencomparesthem.
Sowhathappensisyougetessentially a fourdigitnumberorfourdifferentnumbers.
So, forexample, wehavefournumbers 0000 andthisissomethingwithzerospecificityatall.
Andthewaythat I D's workis, itfillsinthisthirdcalm.
Sothisselectorrightherehasone I d zeroclasses, zeroelementsandzeroinlinestyles.
Soitis a specificityof 0100 Ifwegotonhere, wehave a specificity 001 andthenzeroandThereasonthatthisworksthiswayisbecauseclassestakeupthissecondsectionofthespecificity.
Andifwecomeallthewaydownhereto R H one, thishasthespecificityof 001 andagaintoreiteratethespecificity, thisveryfirstnumberhereontheright, thisisgoingtobethenumberofelements, selectors.
Soeachone a tag p tag, Allofthatgenericelementselectorstuffisgoingtocomeinthisveryfirstnumber.
Soif I comedownhereand I make a styleselectorforinlinestylesand I wanttosetthecolortoforexamplesayinand I saythatyou'llseeourcolorhaschanged a sighinandThat's becausethisisusingthespecificityhereof 1000 So, asyoucantell, thespecificitiesarecalculatedbyfirstlookingatthefirstnumber.
AndthenwehavethisLecterhere 0001 andthishas a selector, whichis 10011 Sothisspecificityisslightlyhigherthanthespecificitydownhere.
Ingeneral, though, youshouldneveruseimportantbecausenowthat I haveimportantonthisredstyle, theonlywaytooverrideimportantistouseanotherimportantstyleandtomakeitmorespecific, so I'd haveto, forexample, stay h onehere.