Blogger Information
Blog 8
fans 0
comment 0
visits 3602
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
选择器权重与伪类选择器
平凡之路
Original
657 people have browsed it

一 选择器权重

代码

  1. /* 选择器的权重
  2. 1 权重大小:mpottant>id>class>标签 */
  3. /* 标签选择器
  4. (1) 标签选择器权重为个位 1个标签个位为1,每加一个标签个位权重+1 */
  5. /* (2)多个标签选择器中间用“空格链接” */
  6. 实例
  7. /* 这个选择器权重(0.0.1) */
  8. h1 {
  9. color: aqua;
  10. }
  11. /* 这个选择器权重(0.0.2) */
  12. body h1 {
  13. color: blue;
  14. }
  15. /* 这个选择器权重(0.0.3) */
  16. body h1 p {
  17. color: rgb(0, 255, 64);
  18. }
  19. /* CLASS选择器 (1)class选择器权重为十位 1个class为10,每加一个class十位权重 + 10 (2)多个class选择器中间用“空格链接” 标签和class相连用 . */
  20. div.aaaa {
  21. color: blueviolet;
  22. }
  23. .b a {
  24. color: rgb(226, 43, 43);
  25. }
  26. .xx {
  27. color: aqua;
  28. }
  29. .ss.xxx {
  30. color: rgb(15, 131, 64);
  31. }
  32. /*id选择器 (1)id选择器权重为百位 1个id为100,每加一个id百位权重 + 100 */
  33. #dd {
  34. color: rgb(255, 0, 0);
  35. }

示例


伪类选择器

代码

  1. /* 伪类选择器 */
  2. /* 结构伪类 */
  3. /* > 伪类,仍是`class`级, 结构伪类用于获取一组元素,所以和上下文选择器一样,需要设置查询起点(父级),否则从根递归 */
  4. /* 1 nth-of-type 匹配唯一的子元素*/
  5. .list > li:nth-of-type(2n + 2) {
  6. color: aqua;
  7. background-color: blue;
  8. }
  9. /* 偶数算法
  10. (2*0+2=2)
  11. (2*1+2=4)
  12. (2*2+2=6)
  13. (2*3+2=8) */
  14. .list1 > li:nth-of-type(2n + 1) {
  15. color: rgb(38, 0, 255);
  16. background-color: rgb(255, 0, 149);
  17. }
  18. /*奇数算法
  19. (2*0+1=1)
  20. (2*1+1=3)
  21. (2*2+1=5)
  22. (2*3+1=7) */
  23. .list2 > li:nth-of-type(n + 5) {
  24. color: rgb(0, 26, 2);
  25. background-color: rgb(255, 0, 0);
  26. }
  27. /* 从第五个开始计算
  28. (0+0+5=5)
  29. (0+1+5=6)
  30. (0+2+5=7)
  31. (0+3+5=7) */
  32. .list3 > li:nth-of-type(-n + 5) {
  33. color: rgb(0, 26, 2);
  34. background-color: rgb(255, 0, 0);
  35. }
  36. /* 从第五个开始计算倒序 */
  37. /* 从第五个开始计算
  38. (0+0+5=5)
  39. (0-1+5=4)
  40. (0-2+5=3)
  41. (0-3+5=2)
  42. (0-4+5=1)
  43. (0-5+5=0)
  44. */
  45. /* first-of-type 匹配分组第一个子元素*/
  46. .list4 > li:first-of-type {
  47. color: rgb(0, 255, 21);
  48. background-color: rgb(140, 0, 255);
  49. }
  50. /* last-of-type 匹配分组最后一个子元素*/
  51. .list5 > li:last-of-type {
  52. color: rgb(0, 255, 21);
  53. background-color: rgb(140, 0, 255);
  54. }
  55. /* first-of-type 匹配分组倒数第三名*/
  56. .list6 > li:nth-last-of-type(-n + 3) {
  57. color: rgb(0, 255, 21);
  58. background-color: rgb(140, 0, 255);
  59. }

示例


Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:代码已经展示出来了,就没有必要再截屏了,直接展示效果图即可
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!