Blogger Information
Blog 18
fans 0
comment 0
visits 7741
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
选择器权重,常用伪类选择器
只如初见
Original
411 people have browsed it

选择器权重

html代码

  1. <h2 class="mytitle" id="idtitle">实例演示</h2>

css代码

  1. /* id: 百位 class: 十位 tag: 个位
  2. 理解最小值:0,0,1 理解最大值:1,1,1
  3. 以下是特例:
  4. !important: 最高指示,忽略任何权重(调试样式)
  5. */
  6. /*
  7. 计算方法
  8. id:0
  9. class: 0
  10. tag: 0
  11. 权重 : 0,0,0 */
  12. /* 0,0,1 */
  13. h2 {
  14. color: blueviolet;
  15. }
  16. /* 0,0,2 */
  17. body h2 {
  18. color: blue;
  19. }
  20. /* 0,1,1 */
  21. h2.mytitle {
  22. color: aqua;
  23. }
  24. /* 1,0,1 */
  25. h2#idtitle {
  26. color: brown;
  27. }

常用伪类选择器

html代码

  1. <ul class="list">
  2. <li>节点1</li>
  3. <li>节点2</li>
  4. <li>节点3</li>
  5. <li>节点4</li>
  6. <li>节点5</li>
  7. <li>节点6</li>
  8. <li>节点7</li>
  9. <li>节点8</li>
  10. </ul>

css代码

  1. /*
  2. :nth-of-type(a*n+b)
  3. 1. a: 系数, [0,1,2,...] 可自己定义数值
  4. 2. n: [0,1,2,3,....] 自变量,默认写n
  5. 3. b: 偏移量, 从0开始 根据需求设置数值
  6. 注: 计算出来的索引,必须是有效, 从1开始
  7. */
  8. /* 获取所有 */
  9. /* .list > * {
  10. background-color: antiquewhite;
  11. } */
  12. .list :nth-of-type(n) {
  13. background-color: aliceblue;
  14. }
  15. /* 获取第一个 */
  16. /*
  17. .list :nth-of-type(1) {
  18. background-color: aliceblue;
  19. } */
  20. .list :first-of-type() {
  21. background-color: aliceblue;
  22. }
  23. /* 获取最后一个 */
  24. .list :last-of-type() {
  25. background-color: aquamarine;
  26. }
  27. /* 获取第三个和第三个之后的所有元素 */
  28. .list :nth-of-type(n + 3) {
  29. background-color: blue;
  30. }
  31. /* 获取第三个和第三个之前的所有元素 */
  32. .list :nth-of-type(-n + 3) {
  33. background-color: blueviolet;
  34. }
  35. /* 获取索引为基数的所有元素 */
  36. /* .list :nth-of-type(2n+1){
  37. background-color: blue;
  38. }
  39. .list :nth-of-type(2n-1){
  40. background-color: blue;
  41. } */
  42. .list :nth-of-type(odd) {
  43. background-color: brown;
  44. }
  45. /* 获取索引为偶数的所有元素 */
  46. /* .list :nth-of-type(2n) {
  47. background-color: burlywood;
  48. } */
  49. .list :nth-of-type(even) {
  50. background-color: burlywood;
  51. }
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!