5.案例准备.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. .box {
  9. width: 800px;
  10. height: 800px;
  11. border: 2px solid #000;
  12. }
  13. #part1 {
  14. width: 200px;
  15. height: 200px;
  16. color: #f00;
  17. font-size: 35px;
  18. font-weight: bold;
  19. background: #ff0;
  20. display: inline-block;
  21. /*想让文字 在 已知宽高的盒子 内 居中*/
  22. text-align: center;
  23. /* 间隔 */
  24. line-height: 200px;
  25. }
  26. #part1:hover {
  27. color: #fff;
  28. background-color: #000;
  29. }
  30. #part2 {
  31. width: 200px;
  32. height: 200px;
  33. color: #ff0;
  34. font-size: 35px;
  35. font-weight: bold;
  36. background: #00f;
  37. display: inline-block;
  38. /*想让文字 在 已知宽高的盒子 内 居中*/
  39. text-align: center;
  40. /* 间隔 */
  41. line-height: 200px;
  42. }
  43. /*
  44. 将块级元素转成行内元素
  45. display:inline
  46. 将元素转成行内块元素
  47. display:inline-block
  48. 将元素转成行块元素
  49. display: block;
  50. */
  51. span {
  52. font-size: 22px;
  53. }
  54. /* 伪类选择器
  55. :hover 滑过
  56. :first-child 第一个子类
  57. :last-child 最后一个子类
  58. :nth-child(n) 自定义子类
  59. even 偶数 2n
  60. odd 奇数 2n+1
  61. */
  62. ul {
  63. /* 取消列表默认样式 */
  64. list-style: none;
  65. }
  66. ul li a {
  67. /* 取消a标签的默认样式 */
  68. text-decoration: none;
  69. color: #000;
  70. }
  71. ul li:first-child a {
  72. color: plum;
  73. }
  74. ul li:last-child a {
  75. color: blue;
  76. }
  77. ul li:nth-child(2n+1) a {
  78. color: #0f0;
  79. }
  80. ul li:nth-child(2n+1):hover a {
  81. color: #ff0;
  82. }
  83. ul li:hover a {
  84. color: red;
  85. }
  86. </style>
  87. </head>
  88. <body>
  89. <div class="box">
  90. <div id="part1">
  91. 你好
  92. </div>
  93. <div id="part2">
  94. <span>1</span>
  95. <span>2</span>
  96. </div>
  97. <ul>
  98. <li><a href="">你好</a></li>
  99. <li><a href="">你好</a></li>
  100. <li><a href="">你好</a></li>
  101. <li><a href="">你好</a></li>
  102. <li><a href="">你好</a></li>
  103. <li><a href="">你好</a></li>
  104. </ul>
  105. </div>
  106. </body>
  107. </html>