Blogger Information
Blog 5
fans 0
comment 0
visits 1636
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
html样式选择器和下拉菜单
寻梦人
Original
413 people have browsed it

html 样式选择器

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. </head>
  9. <body>
  10. <!-- 基本选择器 -->
  11. <h2>1.基本选择器</还>
  12. <p class="aa">php.cn</p>
  13. <!-- 上下文选择器 -->
  14. <h2>2.上下文选择器</h2>
  15. <h3>2-1.父子</h3>
  16. <ul class="list1">
  17. <li class="item">item1</li>
  18. <li class="item">item2
  19. <ul>
  20. <li class="item">item2-1</li>
  21. <li class="item">item2-2</li>
  22. <li class="item">item2-3</li>
  23. </ul>
  24. </li>
  25. <li class="item">item3</li>
  26. </ul>
  27. <h3>2-2.后代</h3>
  28. <ul class="list2">
  29. <li class="item">item1</li>
  30. <li class="item">item2
  31. <ul>
  32. <li class="item">item2-1</li>
  33. <li class="item">item2-2</li>
  34. <li class="item">item2-3</li>
  35. </ul>
  36. </li>
  37. <li class="item">item3</li>
  38. </ul>
  39. <h3>2-3.兄弟</h3>
  40. <ul class="list3">
  41. <li class="item first">item1</li>
  42. <li class="item">item2</li>
  43. <li class="item">item3</li>
  44. </ul>
  45. <h3>2-4.同级</h3>
  46. <ul class="list4">
  47. <li class="item first">item1</li>
  48. <li class="item">item2</li>
  49. <li class="item">item3</li>
  50. </ul>
  51. <!-- 伪类选择器 -->
  52. <h2>3.伪类选择器</h2>
  53. <ul class="list5">
  54. <li class="item">item1</li>
  55. <li class="item">item2</li>
  56. <li class="item">item3</li>
  57. <li class="item">item4</li>
  58. <li class="item">item5</li>
  59. <li class="item">item6</li>
  60. <li class="item">item7</li>
  61. <li class="item">item8</li>
  62. <li class="item">item9</li>
  63. </ul>
  64. </body>
  65. <style>
  66. /* 基本选择 */
  67. .aa {
  68. color: red;
  69. font-size: 1em;
  70. }
  71. /* 父级 */
  72. .list1>.item{
  73. border: thin solid red;
  74. }
  75. /* 后代 */
  76. .list2 .item{
  77. border: thin solid blue;
  78. }
  79. /* 兄弟 */
  80. .list3 .first + *{
  81. background-color: red;
  82. }
  83. /* 同级 */
  84. .list4 .first~*{
  85. background-color: yellow;
  86. }
  87. /* 伪类选择器 */
  88. /* 第一个 */
  89. .list5 .item:first-child{
  90. color: green;
  91. }
  92. /* 最后一个 */
  93. .list5 .item:last-child{
  94. color: blue;
  95. }
  96. /* 前两个 */
  97. .list5 .item:nth-child(-n+2){
  98. background-color: lightgreen;
  99. }
  100. /* 最后两个 */
  101. .list5 .item:nth-last-child(-n+2){
  102. background-color: lightsalmon;
  103. }
  104. /* 偶位数 */
  105. /* 2n===even */
  106. .list5 .item:nth-child(even){
  107. background-color: aqua;
  108. }
  109. /* 奇数位 */
  110. /* 2n+1===odd */
  111. .list5 .item:nth-child(odd){
  112. background-color: lightsalmon;
  113. }
  114. </style>
  115. </html>

下拉菜单:

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. </head>
  9. <body>
  10. <nav>
  11. <label for="menu" class="menu">前端</label>
  12. <input type="checkbox" name="menu" id="menu" />
  13. <ul>
  14. <li>html</li>
  15. <li>css</li>
  16. <li>javascript</li>
  17. </ul>
  18. </nav>
  19. </body>
  20. <style>
  21. * {
  22. margin: 0;
  23. padding: 0;
  24. box-sizing: border-box;
  25. }
  26. #menu {
  27. display: none;
  28. }
  29. ul {
  30. display: none;
  31. }
  32. #menu:checked + ul {
  33. display: block;
  34. }
  35. nav {
  36. width: 6em;
  37. height: 1.6em;
  38. text-align: center;
  39. line-height: 1.6em;
  40. background-color: aqua;
  41. margin: 3em;
  42. border: 1px solid #a3a3a3;
  43. }
  44. nav li {
  45. list-style: none;
  46. border-bottom: 1px solid #a3a3a3;
  47. background-color: aqua;
  48. }
  49. nav li:hover {
  50. cursor: pointer;
  51. background-color: rgb(255, 103, 124);
  52. color: white;
  53. }
  54. </style>
  55. </html>

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