Blogger Information
Blog 7
fans 0
comment 0
visits 4551
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
伪类选择器,优先级,模块化
辰辰
Original
444 people have browsed it

优先级

  • id > class > tag
  • 用公式来计算 id,class,tag => 0,0,0
    实例

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. #id {
  10. color: royalblue;
  11. }
  12. body h1 .class {
  13. color: lightblue;
  14. }
  15. h1 {
  16. color: lightcoral;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <h1 class="class" id="id">Hello</h1>
  22. </body>
  23. </html>

结果

模块化

用nth-of-type可以把html的代码更简洁

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. .ul li:nth-of-type(3) {
  10. background-color: springgreen;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <ul class="ul">
  16. <li>item1</li>
  17. <li>item2</li>
  18. <li>item3</li>
  19. <li>item4</li>
  20. <li>item5</li>
  21. <li>item6</li>
  22. <li>item7</li>
  23. <li>item8</li>
  24. <li>item9</li>
  25. <li>item10</li>
  26. </ul>
  27. </body>
  28. </html>

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