1 前端CSS选择器权重

  1. <div class="box" id="box">我是box</div>
  2. <style>
  3. div{
  4. background-color: red;
  5. /* width失效权重低于(0,1,1) */
  6. width:1000px
  7. }
  8. div.box {
  9. width:300px;height:300px;
  10. /* height失效,权重低于.(1,1,1) */
  11. }
  12. div#box.box{
  13. height:500px;
  14. /* 权重计算过程是 id=(1,0,0) class=(0,1.0) html标签=(0,0,1) 权重高覆盖权重低 */
  15. }
  16. </style>

效果图

2常用伪类选择器

  1. <ul>
  2. <li class="item">item1</li>
  3. <li class="item">item2</li>
  4. <li class="item">item3</li>
  5. <li class="item">item4</li>
  6. <li class="item">item5</li>
  7. <li class="item">item6</li>
  8. <li class="item">item7</li>
  9. <li class="item">item8</li>
  10. <li class="item">item9</li>
  11. <li class="item">item10</li>
  12. <li class="item">item11</li>
  13. </ul>
  14. <style>
  15. /* 第一种常用伪类 鼠标放上去效果 */
  16. li:hover{
  17. background-color: #333;
  18. }
  19. /* 第二种通常在列表中使用某一个或某一组。 :nth-of-type(an+b); */
  20. /* 01选中前三个 */
  21. ul li.item:nth-last-of-type(n+3){
  22. background-color: #555;
  23. }
  24. /* 匹配最后一个 */
  25. ul li.item:last-of-type{
  26. background-color: green;
  27. }
  28. /* 匹配一组 */
  29. ul li.item:nth-last-of-type(1n){
  30. background-color: #22ffcc;
  31. }
  32. /* 匹配偶数组 */
  33. ul li.item:nth-last-of-type(even){
  34. background-color: #22ffcc;
  35. }
  36. /* 匹配奇数组 */
  37. ul li.item:nth-last-of-type(odd){
  38. background-color: #22ffcc;
  39. }
  40. </style>

更多相关文章

  1. 精准匹配企业采购需求,构建多场景数字化采购管理新模式
  2. android : 如何通过provider向外共享数据
  3. Android中判断Intent是否存在的方法
  4. 三、Android下拉框实现
  5. python 包之 re 正则匹配教程
  6. Android如何根据当前显示配置匹配资源 layout / drawable
  7. 选择器权重,伪类选择器计算
  8. Android中添加和识别手势操作
  9. Android

随机推荐

  1. Python机器学习之Logistic回归
  2. 【懒懒的Tensorflow学习笔记三之搭建简单
  3. 求助!为什么我连python的hello word都写不
  4. 【爬虫初探】新浪微博搜索爬虫实现
  5. KNN(K近邻分类器)Python3实现
  6. Python 浅拷贝和深拷贝使用例子
  7. Python.PyGanme -- 用Python写游戏
  8. Python笔记(十一):多线程
  9. python爬虫 scrapy2_初窥Scrapy
  10. 【Python】【面试必看】Python笔试题