TableofContents
1.CascadingstylesheetCSSoutreach
1.1LinkXMLdocuments
?edit
2.Selector
2.1Relationshipselector
2.1.1Nearbysiblingselector
2.2Attributeselector
2.3Pseudo-classselector
2.4Descendantselectors
2.5Commonlyusedselectors
2.5.1TagSelector
2.5.2ClassSelector
2.5.3IDselector
3.CommonCSSproperties
3.1Textattributes
3.2Colorattributes(foregroundcolor)
3.3Backgroundproperties
3.4Borderproperties
4.Commonlayoutattributes
4.1Floating
4.2Positioning
4.1.1Positioningmode
4.2.2.Edgeoffset
5.Commonlayoutattributes
5.1overflowattribute
5.2z-indexattribute
ThereareseveralwaystolinkCSSexternalXMLdocuments:inline,embedded,andexternallink.Themostcommonlyusedistheexternallinktype(i.e.,link-intype),whichputsallstylesinoneormorefileswitha.cssextension.Intheexternalstylesheet,linkthexmlwithspecialstatements,forexample:
<?xmlversion="1.0"encoding="GB2312"?> <?xml-stylesheettype="text/css"href="product.css"?> <product> <description>thisisatoyforchildaged4andabove</description> <price>66.6</price> </product>
description{ font-size:30px; font-style:italic; }
Relationshipselectorsmainlyincludechildelementselectorsandsiblingselectors.
Thechildelementselectorismainlyusedtoselectthefirst-levelchildelementsofanelement,connectedbythe”>”symbol,forexample:A>B.
Therearetwotypesofsiblingselectors:adjacentsiblingselectorsandordinarysiblingselectors.
2.1.1Nearbysiblingselector
Thesiblingselector(+)isusedtoselectthefirstsiblingelementafterthespecifiedelement.Itmustbeimmediatelyfollowingthesiblingelementofthespecifiedelement,andonlyoneelementcanbeselected.
A+B{ color:red; }
2.1.2Commonsiblingselector
Theordinarysiblingselector(~)isusedtoselectalladjacentsiblingelementsbehindanelement(itdoesnotneedtobeimmediatelyadjacent).Itssyntaxformatis”element1~element2″,whereelement1isthefirstelement,element2isthesecondelement,andallsubsequentelement2elementsaresiblingelementsadjacenttothefirstelementelement1.
A~B{ color:red; }
AnattributeselectorisatypeofCSSselectorthatallowselementstobeselectedbasedontheirattributevalues.Byusingattributeselectors,youcanselectspecificelementsbasedontheirattributevalues.Forexample:
a[href=”#”]{
color:blue;
}
Pseudo-classselectorscansetdifferentstylesforelementsbasedondifferentstatesorpositions.
- :link-Selectanunvisitedlinkandsetitsstyle,suchastextcolora:link{background-color:yellow;}
- :visited-Styleforvisitedlinks,suchastextcolor
- :hover-Appliesthestylewhenthemouseishoveringovertheelement
- a:hover{color:red;}
- :active-appliesthestylewhentheelementisactivated(e.g.,clicked)
- :fous-Appliesstylewhenelementgetsfocus
- :first-child-Appliesthestylewhenthespecifiedelementisthefirstchildofitsparentelement
- :last-child-Appliesthestylewhenthespecifiedelementisthelastchildofitsparentelement
DescendantselectorsrefertoCSSselectorsthatselectelementsthroughthenestinglevelofchildelements.Theyaretwoselectorsseparatedbyspaces.Thefirstselectorselectstheparentelement,andthesecondselectorselectsitsdescendantelements.,like:
parentelementchildelement{}
AB{ color:blue; } B{color:red;}
2.5CommonSelectors
Commonselectorpriorities:
IDSelector(weightvalueis100)>Classselector,attributeselector,pseudo-classselector(weightvalueis10)>Labelselector,Pseudoelementselector(weightvalue1).
2.5.1TagSelector
TagselectorsmatchallelementsinanXMLpagethatusethesametag.Youcanaddstylestomarkerstochangetheirsize,color,font,andmore.
Thetagselectordirectlyuseselementandobjectnamesasselectors,asfollows(elementnameisusedasselector)
name{ font-size:20pt; font-wight:bold; }
2.5.2ClassSelector
Aclassselectorisastyleselectorthatstartswithaperiod”.”followedbyaclassname,andisusedtoselectagroupofelementswiththesameclassname.xmlfile
<divclass="example"> <p>HelloWorld!</p> </div>
.my-class{ color:red; }
2.5.3IDselector
SelectanelementthroughtheIDattributeoftheHTMLelement.TheIDattributeneedstobeuniqueintheHTMLdocument.
<divid="example"> <name>HelloWorld!</name> </div>
#example{ color:red; }
font-size:fontsize(usually12px)font-size:12px;
font-family:font(preferablyuseEnglishfont)font-family:Arial;
font-weight:fontweight(100~900,ninelevels,900isthethickest)
font-style:fontstyle,forexamplefont-style:italic;
Textdisplaymode
3.2Colorattribute(foregroundcolor)
Namenotation-color:red;
“#RGB”notation-R,G,andBrepresentthethreeprimarycolorsofred,green,andbluerespectively.Eachcolorisrepresentedbytwodigitsofhexadecimal(white#FFFFFF,black#000000).
3.3Backgroundattributes
Backgroundcolorbackground-color:color;
Backgroundimagebackground-image:URL(“imagename”);
Whethertheimagerepeatstotilethebackgroundbackground-repeat
repeat(tile)/repeat-x(horizontalfilling)/repeat-y(verticaltiling)/no-repeat(notiling)
Specifythepositionofthebackgroundimagebackground-position
Percent/top/center/bottom/left/right
background-color:#ffffff; background-image:url("animal.jpg"); background-repeat:no-repeat; background-psition:100?nter;
3.4Borderattributes
TextborderpropertiesrefertopropertiesthatcanbeusedtodesignandsettheborderaroundtextthroughCSSstyles,including:
- border:Settheborderaroundthetext,includingthestyle,widthandcoloroftheborder.
- border-style:Setthestyleoftheelementborder.Thefollowingvaluesarecommonlyused:none:noborder/solid:solidborder/dashed:dottedborder/dotted:dottedborder/double:doubleborder
- padding:paddingproperty,usedtosetthespacingbetweentextandborders.
- margin:Marginattribute,usedtosetthespacingbetweenthetextborderandsurroundingelements.
- border-radius:Setthecornerradiusoftheborder.
- box-shadow:Settheshadoweffectaroundthetext,etc.
4.Commonlayoutattributes
4.1Floating
Floatingthelabelreferstoremovingthelabelelementfromthedocumentflowsothatitcanmovefreelywithintheparentcontainer(DIVbox).Floatedelementscanbedisplayedalongsideotherelementswithouttakinguptheentirerow.
Thefloatattributecantakeonthefollowingvalues:
- Theareawherethelabelissettofloatwillcovertheunfloatedarea.
- Sincethefloatingtagnolongeroccupiesthepositionoftheoriginaldocumentflowandwillaffectthelayoutofothertags,youneedtousecleartoclearthefloatingtag,selector{clear:attributevalue;}
4.2Positioning
Labelpositioningreferstospecifyingthepositionofanelementonthepagethroughtheselectionoflabelsandthesettingofattributevalues.Thepositioningpropertiesoflabelsmainlyincludepositioningmodeandedgeoffset.
4.1.1Positioningmode
Thesyntaxformatofusingthepositionattributetopositionatagis:selector{position:attributevalue;}
relative
relativepositioning
absolute
absolutepositioning
fixed
Fixedpositioning
4.2.2.Edgeoffset
Usedtospecifythedistanceoftheboxborderfromtheedgeoftheelementitcontains.Youcansetdifferentoffsetvaluesforthetop,right,bottom,andleftbordersoftheboxbyusingtheedgeoffsetproperty.
5.1overflowattribute
Whenthecontentinthecontainerexceedsthesizeofthecontainer,youneedtousetheoverflow
attributetocontrolhowtheoverflowedcontentisdisplayed.
visible
:Defaultvalue,thecontentwillnotbecroppedandwillbepresentedoutsidethelabelbox.hidden
:Whenthecontentexceedstheboundariesofthecontainer,itwillbecroppedandinvisible.scroll
:Whenthecontentexceedstheboundaryofthecontainer,thescrollbarwillbedisplayedandthecontentcanbescrolled.auto
:Similartoscroll
,thedifferenceisthatthescrollbarwillnotbedisplayedwhenthecontentdoesnotoverflow.
5.2z-indexattribute
Controlsthestackingorderofelementsinastackingcontextbyspecifyingdifferentz-indexvaluestodeterminewhichelementisaboveorbelow.Elementswithhigherz-indexoverwriteelementswithlowerz-index.
Thez-indexattributeacceptspositiveintegers,negativeintegers,and0asvalues,andthedefaultvalueisauto.Thelargerthepositiveintegervalue,thehigherthehierarchyandthemorelikelytheelementwillappearatthetop.Thesmallerthenegativeintegervalue,thelowerthelevelandthemorelikelytheelementwillappearatthebottom.Ifmultipleelementshavethesamez-indexvalue,theirstackingorderwillbedeterminedbasedontheorderinwhichtheyappearintheXMLdocument.b2>b1
#b1{ z-index:1; } #b2{ z-index:2; }