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>伪类参数的选择</title>
  8. </head>
  9. <body>
  10. <ul class="list">
  11. <li>item1</li>
  12. <li>item2</li>
  13. <li class="three">item3</li>
  14. <li>item4</li>
  15. <li>item5</li>
  16. <li>item6</li>
  17. <li>item7</li>
  18. <li>item8</li>
  19. </ul>
  20. <style>
  21. /*
  22. :nth-of-type(an+b)
  23. 1、a:系数,[0.1.2....] 单个还是一组
  24. 2、n:系数,[0.1.2.3....]
  25. 3、b:偏移量
  26. 选择的情况:选择一个,选择一组
  27. */
  28. /* 1.匹配单个,a=0 0n可以缩写 */
  29. /* .list> :nth-of-type(0n + 3) {
  30. background-color: greenyellow;
  31. } */
  32. /* 2.匹配一组 a=1*/
  33. /* .list> :nth-of-type(n) {
  34. background-color: hotpink;
  35. } */
  36. /* 实际开发过程中,使用n+b(偏移量)来匹配元素 */
  37. /* 任务:匹配第3个元素后面的所有兄弟元素 */
  38. /* .list.three,
  39. .list .three~* {
  40. background-color: hotpink;
  41. } */
  42. /* an+n=1n+3
  43. n+3,从第三个开始 */
  44. /* .list> :nth-of-type(n + 3) {
  45. background-color: rgb(0, 130, 33);
  46. } */
  47. /* n:从0开始,n+3匹配全过程
  48. 1. n=0 n+3=3
  49. 2. n=1 n+3=4
  50. ....
  51. 6. n=5 n+3=8 匹配第八个
  52. 7. n=6 n+6=9 索引失败,匹配失败 */
  53. /* a=-1试试看,和a=1是一样的,但是反向取 */
  54. /* .list> :nth-of-type(-n + 3) {
  55. background-color: rgb(0, 130, 33);
  56. } */
  57. /* -1
  58. -2
  59. -3
  60. -4
  61. 以此往下计算 */
  62. /* 如果匹配最后三个 */
  63. /*
  64. .list> :nth-last-of-type(-n + 3) {
  65. background-color: rgb(0, 130, 33);
  66. } */
  67. /* 2.3 a=2:匹配奇偶位置的元素 */
  68. .list> :nth-of-type(2n) {
  69. background-color: khaki;
  70. }
  71. .list> :nth-of-type(2n + 1) {
  72. background-color: rgb(140, 240, 165);
  73. }
  74. /* 2n:even 2n+1:odd */
  75. .list> :nth-of-type(even):hover {
  76. /* 鼠标悬停偶数行,红色背景 */
  77. background-color: #ee1010;
  78. }
  79. </style>
  80. <!-- 表单伪类 -->
  81. <input type="" name="" value="" />
  82. <input type="text" name="" disabled />
  83. <input type="radio" name="sex" value="0" id="m" />
  84. <label for="m"></label>
  85. <input type="radio" name="sex" value="1" id="" />
  86. <label for=""></label>
  87. <br />
  88. <p></p>
  89. <button>提交</button>
  90. <style>
  91. input:disabled {
  92. background-color: yellow;
  93. }
  94. input:enabled {
  95. background-color: rgb(165, 147, 165);
  96. }
  97. input:checked+label {
  98. color: red;
  99. }
  100. button {
  101. width: 100px;
  102. height: 30px;
  103. border: none;
  104. outline: none;
  105. background-color: seagreen;
  106. color: white;
  107. }
  108. button:hover {
  109. background-color: yellow;
  110. }
  111. input:focus {
  112. background-color: tomato;
  113. }
  114. </style>
  115. </body>
  116. </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>选择器3:伪类</title>
  8. </head>
  9. <body>
  10. <!-- 伪类:伪,表示假的,类,权重,class级别 -->
  11. <!-- 伪类
  12. 1.结构伪类:根据元素位置获取元素
  13. 2.状态伪类:根据状态来获取元素
  14. -->
  15. <!-- 重点学习结构伪类 -->
  16. <!-- ul.list>li*8{item$} -->
  17. <ul class="list">
  18. <li class="first">item1</li>
  19. <li>item2</li>
  20. <li>item3</li>
  21. <li>item4</li>
  22. <li>item5</li>
  23. <li>item6</li>
  24. <li>item7</li>
  25. <li>item8</li>
  26. <p>aaa</p>
  27. <p>bbb</p>
  28. <p>ccc</p>
  29. </ul>
  30. <style>
  31. /* 结构伪类:主要是为了选择子元素的,要给予一个选择的起点 */
  32. /* .list> :first-child {
  33. background-color: yellow;
  34. } */
  35. /* 分组结构伪类:以后只用这个 */
  36. .list .first {
  37. background-color: turquoise;
  38. }
  39. .list>li:nth-of-type(1) {
  40. background-color: tomato;
  41. }
  42. .list>li:nth-last-of-type(1) {
  43. background-color: tomato;
  44. }
  45. .list>li :first-of-type {
  46. background-color: greenyellow;
  47. }
  48. </style>
  49. </body>
  50. </html>

更多相关文章

  1. Android(安卓)开发布局 线性布局---LinearLayout
  2. Android布局文件的属性值解析
  3. android中数据存储及对xml的解析
  4. Android面试复习(Android篇一)
  5. Android(安卓)背景透明度设置和设置GridView元素间距
  6. [androidUI]一些布局
  7. Android周学习Step By Step(4)--界面布局
  8. MySQL组合索引与最左匹配原则详解
  9. Android(安卓)内容提供者ContentProvider

随机推荐

  1. Android basic1
  2. Android--动态添加控件
  3. android设备信息获取
  4. android手机QQ尾巴修改(QQ for Pad)
  5. Android 开发 官方 论坛
  6. Android-sharedUserId
  7. android常用颜色代码定义
  8. 怎样更新Android SDK1.1 到 Android SDK1
  9. Android Support Library 23.2
  10. Android(安卓)动画特效的运用