documentcss

csshack  时间:2021-02-11  阅读:()
CSSCASCADETypesofstylesheetsHTMLdocumentsmayhavethreetypesofstylesheetsappliedtothem.
Type1:User-agentstylesIfyoulookatawebpageinabrowser,evenawebpagewithoutanyCSSleattached,therearesomestylesalreadyinplace.
Headingsareoftenlargerinsize.
Unvisitedlinksareoftenblue,visitedlinksareoftenpurpleandallgeneralcontentisoftenblack.
ThisisbecauseallbrowsershavetheirownstylesheetthatisusedtodenethedefaultbehaviourofHTMLelements.
Thisstylesheetismoreaccuratelyreferredtoasa"user-agent"stylesheet.
Type2:Userstyles"Users"arethepeoplewhovisitourwebsitesandinteractwithourcontent.
Manybrowsershavesomesortofmechanismthatallowsuserstowritetheirownstylesheetorstylesheets.
Thesestylesheetsarereferredtoas"userstylesheets".
Userstylesheetsallowsuserstooverridestylesheetsforspecicwebsitesorforallwebsitesthattheyvisit.
Anexamplecouldbeauserwithavisionimpairmentwhowritesastylesheetthatturnsalltextwhiteandthepagebackgroundtoblack-tomakecontenteasiertoread.
Type3:AuthorstylesAswebauthors,wecanusethreedierentmethodstoapplyCSSstylestoanyHTMLdocument.
InlinestylesareappliedtoelementsintheHTMLmarkupusingthe"style"attribute.
!
!
!
Contenthere!
HeaderstylesareplacedintheheadofHTMLdocumentsusingtheelement.
!
!
!
!
!
!
Sitename!
!
!
!
!
p{color:green;}!
!
!
!
!
!
Externalstylesheetsareappliedusingelement.
!
!
!
!
!
!
Sitename!
!
!
!
!
!
NormalvsimportantUsersandauthorscandeneanydeclarationas"moreimportant"thanotherdeclarations.
Importantdeclarationsarewrittenwiththe"!
"delimitertokenand"important"keywordfollowingthedeclaration.
/*exampleofimportant*/!
h2{color:red!
important;}Aswewillseesoon,theCSSCascadetreatsimportantdeclarationsdierentlytonormaldeclarations.
UnderstandingConictBrowsers(oruser-agents)havetodealwithCSSrulescomingfromthesethreedierentorigins-user-agent,userandauthor.
BrowsershavetodealwithCSSrulescomingfromdierenttypesofauthorstylesheets-inlinevsheadervsexternal.
Browsersalsohavetodealwithdierenttypesofdeclarations-importantvsnormal.
Atsomepoint,browsershavetodealwithdeclarationsthatconict.
Conictiswheremorethanonedeclarationreferstothesameelementandproperty.
/*conflictingrules*/!
h2{color:blue;}!
h2.
intro{color:green;}!
.
containerh2{color:red;}Whenconictoccurs,browsersneedtodeterminewhichdeclarationswill"win"(beappliedtoanHTMLdocument).
InCSS2.
1,therearefourstepstodeterminewhichdeclarationwill"win".
Step1GatherthedeclarationsBrowsersmustgatherallthedeclarationsthatapplytoanelementandpropertyfromuser-agent,userandauthorstylesheets.
Forexample,browsershavetogatheranydeclarationsthatmatch:element=h2property=color/*user-agentstyles*/!
h2{color:black;}!
!
/*userstyles*/!
h2{color:green;}!
!
/*authorstyles*/!
h2{color:blue;}!
#navh2{color:lime;}!
!
Iftherearedeclarationsfrommorethanoneofthesethreesources,proceedtostep2.
Step2SortbyoriginandimportanceForthissecondstep,thegathereddeclarationsaresortedaccordingtoorigin(user-agent,user,author)andimportance(normalorimportant).
InCSS2.
1,therearevestepstodeterminehowdeclarationsaresorted.
Fromlowesttohighestpriority!
1.
Normaluser-agentdeclarations2.
Normaluserdeclarations3.
Normalauthordeclarations4.
Importantauthordeclarations5.
ImportantuserdeclarationsIfnootherdeclarationsexist,user-agentdeclarationswin.
/*user-agentstyles*/!
h2{color:black;}Normaluserdeclarationsbeatuser-agentdeclarations.
/*user-agentstyles*/!
h2{color:black;}!
!
/*userstyles*/!
h2{color:green;}Normalauthordeclarationsbeatuser-agentdeclarationsandnormaluserdeclarations.
/*user-agentstyles*/!
h2{color:black;}!
!
/*userstyles*/!
h2{color:green;}!
!
/*authorstyles*/!
h2{color:blue;}Importantauthordeclarationsbeatallnormaldeclarations.
/*user-agentstyles*/!
h2{color:black;}!
!
/*userstyles*/!
h2{color:green;}!
!
/*authorstyles*/!
h2{color:blue;}!
h2{color:purple!
important;}Importantuserdeclarationsbeatimportantauthordeclarationsandallnormaldeclarations.
/*user-agentstyles*/!
h2{color:black;}!
!
/*userstyles*/!
h2{color:green;}!
h2{color:red!
important;}!
!
/*authorstyles*/!
h2{color:blue;}!
h2{color:purple!
important;}Butwhatiftwodeclarationshavethesameoriginorimportance/*user-agentstyles*/!
h2{color:black;}!
!
/*userstyles*/!
h2{color:green;}!
h2{color:red;}!
!
/*authorstyles*/!
h2{color:blue;}!
h2{color:lime;}!
!
IfdeclarationshavethesameoriginorimportancethenproceedtoStep3.
Step3DeterminespecicityIfdeclarationshavethesameoriginorimportancethenthedeclaration'sselectorsneedtobescoredtoseewhichdeclarationwill"win".
Fourscoresareconcatenated(linkedtogetherasachain)tocreateanalscore.
Thisscoreisreferredtoasaselector'sspecicity.
!
selectorspecicity=a,b,c,dHowisspecicitycalculatedA.
Isthereaninlinestyle!
!
!
a=1xinlinestyles!
b=0xIDs!
c=0xclasses,pseudo-classes,attributes!
d=0xelements,pseudo-elements!
!
Specificity=1,0,0,0B.
CountthenumberofIDselectorsintheselector.
#nav{}!
!
!
a=0xinlinestyles!
b=1xIDs!
c=0xclasses,pseudo-classes,attributes!
d=0xelements,pseudo-elements!
!
Specificity=0,1,0,0!
C.
Countthenumberofclassselectors,attributeselectorsorpseudo-classselectorsintheselector.
.
intro{}!
!
!
a=0xinlinestyles!
b=0xID!
c=1xclasses,pseudo-classes,attributes!
d=0xelements,pseudo-elements!
!
Specificity=0,0,1,0!
D.
Countthenumberofelementtypeorpseudo-elementselectorsintheselector.
p{}!
!
!
a=0xinlinestyles!
b=0xID!
c=0xclasses,pseudo-classes,attributes!
d=1xelements,pseudo-elements!
!
Specificity=0,0,0,1E.
Ignoretheuniversalselector.
*{}!
!
!
a=0xinlinestyles!
b=0xID!
c=0xclasses!
d=0xelement!
!
Specificity=0,0,0,0Someexamples#navul{}!
!
!
a=0xinlinestyles!
b=1xID(#nav)!
c=0xclasses!
d=1xelement(ul)!
!
Specificity=0,1,0,1blockquote.
special{}!
!
!
a=0xinlinestyles!
b=0xIDs!
c=1xclass(.
special)!
d=1xelement(blockquote)!
!
Specificity=0,0,1,1a:link{}!
!
!
a=0xinlinestyles!
b=0xIDs!
c=1xpseudo-class(:link)!
d=1xelements(a)!
!
Specificity=0,0,1,1input[required]{}!
!
!
a=0xinlinestyles!
b=0xIDs!
c=1xattributeselector([required])!
d=1xelements(input)!
!
Specificity=0,0,1,1p[class="a"]{}!
!
!
a=0xinlinestyles!
b=0xIDs!
c=1xattributeselector([class="a"])!
d=1xelements(p)!
!
Specificity=0,0,1,1div[id="news"]{}!
!
!
a=0xinlinestyles!
b=0xIDs!
c=1xattributeselector([id="news"])!
d=1xelements(div)!
!
Specificity=0,0,1,1::first-line{}!
!
!
a=0xinlinestyles!
b=0xIDs!
c=0xclasses!
d=1xpseudo-element(::first-line)!
!
Specificity=0,0,0,1#navullia:hover{}!
!
!
a=0xinlinestyles!
b=1xID(#nav)!
c=1xpseudo-class(:hover)!
d=3xelements(ul,li,a)!
!
Specificity=0,1,1,3AnoteonconcatenationGenerallyspeaking,"A"willalwaysbeat"B",whichwillalwaysbeat"C",whichwillalwaysbeat"D".
NomatterhowmanyIDsareusedinaselector,aninlinestylewillalwaysbeatanIDselector.
Inthefollowingexample,theinlinestylewinsduetospecicity-1,0,0,0beats0,10,0,0.
/*authorstyles*/!
#one#two#three#four#five#six#seven#eight#nine#ten!
{color:green;}!
!
!
!
Theoretically,nomatterhowmanyclassesareappliedtoaselector,anIDwillalwaysbeatclasses.
!
(Firefoxbrowsersincorrectlyimplementthespecicationsothat256classeswill"beat"anID)Inthefollowingexample,theIDselectorwinsduetospecicity-0,1,0,0beats0,0,10,0.
/*authorstyles*/!
.
one.
two.
three.
four.
five.
six!
.
seven.
eight.
nine.
ten!
{color:green;}#nav{color:lime;}Theoretically,nomatterhowmanyelementtypesareappliedtoaselector,aclasswillalwaysbeatelementtypes.
!
(Firefoxbrowsersincorrectlyimplementthespecicationsothat256elementtypeswill"beat"aclass)Inthefollowingexample,theclassselectorwinsduetospecicity-0,0,1,0beats0,0,0,10.
/*authorstyles*/!
divdivdivdivdivdivdivdivdivdiv{color:green;}.
intro{color:lime;}WhatifthereisstillnoclearwinnerInthefollowingexample,twoauthorstyleshavethesamespecicity.
/*authorstyles*/!
.
introh2{color:blue;}!
h2.
new{color:lime;}!
!
!
!
!
!

无忧云:洛阳BGP云服务器低至38.4元/月起;雅安高防云服务器/高防物理机优惠

无忧云怎么样?无忧云,无忧云是一家成立于2017年的老牌商家旗下的服务器销售品牌,现由深圳市云上无忧网络科技有限公司运营,是正规持证IDC/ISP/IRCS商家,主要销售国内、中国香港、国外服务器产品,线路有腾讯云国外线路、自营香港CN2线路等,都是中国大陆直连线路,非常适合免备案建站业务需求和各种负载较高的项目,同时国内服务器也有多个BGP以及高防节点。一、无忧云官网点击此处进入无忧云官方网站二...

简单测评melbicom俄罗斯莫斯科数据中心的VPS,三网CN2回国,电信双程cn2

melbicom从2015年就开始运作了,在国内也是有一定的粉丝群,站长最早是从2017年开始介绍melbicom。上一次测评melbicom是在2018年,由于期间有不少人持续关注这个品牌,而且站长貌似也听说过路由什么的有变动的迹象。为此,今天重新对莫斯科数据中心的VPS进行一次简单测评,数据仅供参考。官方网站: https://melbicom.net比特币、信用卡、PayPal、支付宝、银联...

NameCheap黑色星期五和网络礼拜一

如果我们较早关注NameCheap商家的朋友应该记得前几年商家黑色星期五和网络星期一的时候大促采用的闪购活动,每一个小时轮番变化一次促销活动而且限量的。那时候会导致拥挤官网打不开迟缓的问题。从去年开始,包括今年,NameCheap商家比较直接的告诉你黑色星期五和网络星期一为期6天的活动。没有给你限量的活动,只有限时六天,这个是到11月29日。如果我们有需要新注册、转入域名的可以参加,优惠力度还是比...

csshack为你推荐
处理器flash供应商搜狗浏览器2徐州发布官方微信复核chrome支持ipad重庆网通中国联通重庆分公司的公司简介netbios端口如何组织netbios端口的外部通信重庆宽带测速重庆联通宽带测速的网址是好多呢?iphone连不上wifi为什么苹果手机连不上wifi微信都发不出去?phpechophp echo函数 是什么意思
视频空间租用 qq空间域名 荷兰服务器 主机 themeforest isatap 国内永久免费云服务器 vmsnap3 payoneer nerd 香港新世界电讯 ev证书 世界测速 isp服务商 爱奇艺vip免费试用7天 电信虚拟主机 中国电信宽带测速器 raid10 网购分享 英国伦敦 更多