Download - All IT eBooks
Transcript
40
MoreCSSselectors
ACSSselectoriseverythingonthefirstlinethatprecedesthe{.It’sthepartofa
stylerulethattellsthebrowserwhatelements,classes,andidsaruleappliesto.The
selectorsarehighlightedinthefollowingcodefragments.
p{
p.special{
.special{
p#intro{
#intro{
Sofaryou’velearnedtocreate…
1. Anelementselectorlikep,div,orimg.
2. Anelementclassselectorlikep.special,div.important,orimg.gallery.
3. Aclassselectortiedtonoparticulartypeofelementlike.special,.important,
or.gallery.
4. Anelementidselectorlikep#intro,div#sidebar,orimg#logo.
5. Anidselectortiedtonoparticulartypeofelementlike#intro,#sidebar,or
#logo.
Youcancombineselectorstocreatemorecomplicatedselectors.Here’sone.
div.importantp{
Thecodeaboveselectsallparagraphsinadivthat’sbeenassignedtheclass
“important.”
Thefollowingcodeselectsallimages…thatareinlistitems…inanunorderedlist…
withtheid“pix-list.”
ul#pixListliimg{
Here’ssomecodethatselectsthefirstparagraphfollowinganydiv.
div+p{
Thefollowingcodeselectsonlythefirstlevelofdivswithinthedivthathasanid
of“main.”
div#content>div{
Sointhefollowingcode,onlythehighlighteddivsareselected.
<divid=“main”>