Blogger Information
Blog 5
fans 0
comment 0
visits 2435
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
【css权重计算、伪类】
以前真好
Original
546 people have browsed it

CSS权重计算

按照#id、类class、标签:tag的顺序排列进行权重计算

id>class>tag

  1. <style>
  2. .item{
  3. /* 权重(0,1,0) */
  4. }
  5. span.item{
  6. /* 权重(0,1,1) */
  7. }
  8. div .item{
  9. /* 权重(0,1,2) */
  10. }
  11. #ID .item{
  12. /* 权重(1,1,0) */
  13. }
  14. .su .item{
  15. /* 权重(0,2,0) */
  16. }
  17. .active.item{
  18. /* 权重(0,2,0) */
  19. }
  20. /* !important为调试代码使用 权重最高 */
  21. </style>
  22. <div class="su">
  23. <span class="item active" id="ID">1111</span>
  24. </div>

伪类选择

  1. <style>
  2. ul li:nth-of-type(2){
  3. color: red;
  4. }
  5. ul li:first-of-type{
  6. color: yellow;
  7. }
  8. ul li:last-of-type{
  9. color: blue;
  10. }
  11. ul li:nth-of-type(odd){
  12. background: red;
  13. }
  14. ul li:nth-of-type(even){
  15. background: yellowgreen;
  16. }
  17. </style>
  18. <ul>
  19. <li>1</li>
  20. <li>2</li>
  21. <li>3</li>
  22. <li>4</li>
  23. <li>5</li>
  24. <li>6</li>
  25. <li>7</li>
  26. <li>8</li>
  27. <li>9</li>
  28. <li>10</li>
  29. </ul>
  30. <style>
  31. /* 获取偶数索引的元素;匹配一组a=[1,-1,2] 这里面a=2 n=n b=0 2n+0=2n n取值(0,1,2,3...)
  32. 因为:nth-of-type(an+b): 计算出来的索引,必须是有效的, 且从 1 开始的正整数
  33. 所以计算出来的是2,4,6,8...即:nth-of-type(2n)是获取偶数索引的元素 */
  34. /* 取偶数行 */
  35. div p:nth-of-type(2n) {
  36. color: red;
  37. }
  38. div p:nth-of-type(2n+1){
  39. color: aqua;
  40. }
  41. /* 同上计算方法,计算出来的是1,3,5,7..即:nth-of-type(2n+1)是获取奇数索引的元素 */
  42. </style>
  43. <div>
  44. <p>1</p>
  45. <p>2</p>
  46. <p>3</p>
  47. <p>4</p>
  48. <p>5</p>
  49. </div>
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