More Related Content Similar to CSS Cascade [译] Similar to CSS Cascade [译] (17) CSS Cascade [译]31. 收集到的声明 h2 { color: black; } h2 { color: green; } h2 { color: blue; } #nav h2 { color: lime; } Browser style sheet User style sheet Author style sheets 39. 优先级由低到高 1 浏览器样式 2 用户样式里的普通声明 3 作者样式里的普通声明 4 作者样式里的!important声明 5 用户样式里的!important声明 40. 1. 浏览器样式 h2 { color: black; } 如果不存在其他声明, 浏览器声明获胜 Browser style sheet User style sheet Author style sheets 41. 2. 普通用户样式 h2 { color: black; } Browser style sheet 普通用户声明胜过浏览器声明 h2 { color: green; } User style sheet Author style sheets 42. 3. 普通作者样式 h2 { color: black; } Browser style sheet 普通作者声明胜过浏览器声明和普通用户声明 h2 { color: green; } h2 { color: blue; } User style sheet Author style sheets 43. 4. !important作者样式 h2 { color: black; } Browser style sheet !important 作者声明胜过所有普通声明 h2 { color: green; } h2 { color: blue; } h2 { color: lime !important; } User style sheet Author style sheets 44. 5. !important用户样式 h2 { color: black; } Browser style sheet !important 用户声明胜过 !important 作者声明 和所有普通声明 h2 { color: green; } h2 { color: red !important;} h2 { color: blue; } h2 { color: lime !important; } User style sheet Author style sheets 46. 有两条匹配的声明 h2 { color: black; } h2 { color: green; } Browser style sheet User style sheet 两条来源和重要性相同的声明 h2 { color: blue; } h2 { color: lime; } Author style sheets 50. 选择器 #nav h2 { color: blue; } h2.intro { color: red; } 选择器 54. A. 是不是内联样式? <h2 style=“color: red;”> This is a heading a = 1 x </h2> inline styles b = 0 x ID<p> c = 0 x classes Here is a paragraph of d = 0 x element Specificity = 1,0,0,0 55. B. 统计选择器中ID的数量. #nav{ color: red; } a = 0 x inline styles b = 1 x ID c = 0 x classes d = 0 x element Specificity = 0,1,0,0 56. C. 统计class,属性和 伪类的数量. .main { color: red; } a = 0 x inline styles b = 0 x ID c = 1 x classes d = 0 x element Specificity = 0,0,1,0 57. D. 统计元素名和伪元素的数量. h2 { color: red; } a = 0 x inline styles b = 0 x ID c = 0 x classes d = 1 x element Specificity = 0,0,0,1 61. External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) #one #two #three #four #five #six #seven #eight #nine #ten { color: green; } <h2 style=“color: purple;”> 高亮的样式胜出因为优先级 1,0,0,0 胜过0,10,0,0 63. External style sheets and header styles (Author styles) .one .two .three .four .five .six .seven .eight .nine .ten { color: green; } #nav { color: lime; } 高亮的样式胜出因为优先级 0,1,0,0 胜过 0,0,10,0 65. External style sheets and header styles (Author styles) div div div div div form fieldset div label span { color: green; } .intro { color: lime; } 高亮的样式胜出因为优先级 0,0,1,0 胜过 0,0,0,10 67. ID和元素 #nav h2 { color: red; } a = 0 x inline styles b = 1 x ID (#nav) c = 0 x classes d = 1 x element (h2) Specificity = 0,1,0,1 68. 元素和class h2.intro { color: red; } a = 0 x inline styles b = 0 x ID c = 1 x classes (.intro) d = 1 x element (h2) Specificity = 0,0,1,1 69. ID, 元素和伪类 #navul li a:hover { color: a = 0 x inline styles b = 1 x ID (#nav) c = 1 x pseudo-class (:hover) d = 3 x elements (ul, li, a) Specificity = 0,1,1,3 70. 元素和伪元素 p:first-line { color: green a = 0 x inline styles b = 0 x ID c = 0 x classes d = 2 x element (p) and pseudo-element (:first-line) Specificity = 0,0,0,2 71. 元素和属性选择器 h2[title=“intro”] { color: a = 0 x inline styles b = 0 x ID c = 1 x attribute selector ([title=“intro”]) d = 1 x element (h2) Specificity = 0,0,1,1 77. 同等的声明 #nav h2 { color: green; } #nav h2 { color: red; } 第二条声明获胜,因为他写在 第一条后面. 81. Browser style sheet User style sheet External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: black; } h2 { color: green; } 82. Browser style sheet User style sheet h2 { color: black; } h2 { color: green; } 普通用户声明从来源上胜过浏览器声明 External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) 84. Browser style sheet User style sheet External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: black; } h2 { color: green; } h2 { color: blue; } 85. Browser style sheet User style sheet External style sheets and header styles (Author styles) h2 { color: black; } h2 { color: green; } h2 { color: blue; } 作者声明从来源上胜过浏览器和用户声明 HTML document with inline styles (Author styles) 87. Browser style sheet User style sheet External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: black; } h2 { color: green; } h2 { color: blue; } <h2 style=“color: purple;”> 88. Browser style sheet h2 { color: black; } User style sheet h2 { color: 普通内联声明胜过普通外部和头部声明,因为 优先级 1,0,0,0 胜过0,0,0,1 External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: blue; } <h2 style=“color: purple;”> 90. Browser style sheet User style sheet External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: black; } h2 { color: green; } h2 { color: blue; } h2 { color: lime !important; } <h2 style=“color: purple;”> 91. Browser style sheet User style sheet h2 { color: black; } h2 { color: green; } !important 作者样式 胜过普通浏览器、用户 和作者样式 External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: blue; } h2 { color: lime !important; } <h2 style=“color: purple;”> 93. Browser style sheet User style sheet External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: black; } h2 { color: green; } h2 { color: blue; } h2 { color: lime !important; } <h2 style=“color: purple !important;”> 94. Browser style sheet h2 { color: black; } User style sheet !important 内联作者声明胜过 !important 外部作者 声明和头部声明,因为优先级 1,0,0,0 胜过 0,0,0,1 External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: blue; } h2 { color: lime !important; } <h2 style=“color: purple !important;”> 96. Browser style sheet User style sheet External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: black; } h2 { color: green; } h2 { color: gray !important; } h2 { color: blue; } h2 { color: lime !important; } <h2 style=“color: purple !important;”> 97. Browser style sheet h2 { color: black; !important 用户声明胜过 !important 作者声明 (不管他们是外部、头部还是内联) User style sheet External style sheets and header styles (Author styles) HTML document with inline styles (Author styles) h2 { color: green; } h2 { color: gray !important; } h2 { color: blue; } h2 { color: lime !important; } <h2 style=“color: purple !important;”> 100. External style sheets and header styles (Author styles) h2.news { color: #eee; } h2 { color: blue; } 101. 高亮的声明胜出,因为优先级 0,0,1,1 胜过 0,0,0,1 External style sheets and header styles (Author styles) h2.news { color: #eee; } h2 { color: blue; } 103. External style sheets and header styles (Author styles) h2.news { color: #eee; } h2 { color: blue; } h2.news { color: green; } 106. External style sheets and header styles (Author styles) #nav h2 { color: lime; } h2.news { color: #eee; } h2 { color: blue; } h2.news { color: green; } 107. 高亮的选择器胜出, 因为优先级 0,1,0,1 胜过 0,0,1,1 和0,0,0,1 External style sheets and header styles (Author styles) #nav h2 { color: lime; } h2.news { color: #eee; } h2 { color: blue; } h2.news { color: green; } 109. External style sheets and header styles (Author styles) #nav h2 { color: lime; } h2.news { color: #eee; } h2 { color: blue; } h2.news { color: green; } div#nav h2 { color: lime; } 110. 高亮的选择器胜出, 因为优先级 0,1,0,2 胜过 0,1,0,1 和 0,0,1,1 和0,0,0,1 External style sheets and header styles (Author styles) #nav h2 { color: lime; } h2.news { color: #eee; } h2 { color: blue; } h2.news { color: green; } div#nav h2 { color: lime; }