5.垂直导航.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /* 取消ul默认样式 */
  9. ul {
  10. list-style: none;
  11. }
  12. /* 取消a标签的默认样式 */
  13. /*
  14. text-decoration:
  15. none 消除
  16. underline 下划线
  17. overline 上划线
  18. line-through 删除线
  19. */
  20. a {
  21. text-decoration: none;
  22. color: #ff0;
  23. /* text-decoration: line-through; */
  24. }
  25. ul li {
  26. width: 100px;
  27. height: 80px;
  28. background: #f00;
  29. /* 在已知宽高的盒子内文字居中 */
  30. /* 水平居中 */
  31. text-align: center;
  32. /* 垂直居中 */
  33. line-height: 80px;
  34. margin-top: 10px;
  35. }
  36. /* ul li:nth-child(2n+1) {
  37. background: #ff0;
  38. }
  39. ul li:nth-child(2n+1) a{
  40. color: #f00;
  41. } */
  42. /* 划过效果 */
  43. ul li:hover {
  44. background: #00f;
  45. }
  46. ul li:hover a {
  47. color: #0f0;
  48. }
  49. ul li:first-child:hover {
  50. /* 显示元素 */
  51. /* display: block; */
  52. }
  53. span {
  54. width: 100px;
  55. height: 50px;
  56. background: #0ff;
  57. /* 将元素转成块级元素 */
  58. display: block;
  59. }
  60. #content div {
  61. width: 200px;
  62. height: 200px;
  63. /* 隐藏元素 */
  64. /* display: none; */
  65. /* 将元素转成行内元素 */
  66. /* display: inline; */
  67. /* 将元素转成行内块元素 */
  68. display: inline-block;
  69. }
  70. #partOne {
  71. background: #00f;
  72. color: #0f0;
  73. display: none;
  74. display: block;
  75. }
  76. #part-two {
  77. background: #0ff;
  78. color: #00f;
  79. }
  80. #partThree {
  81. background: #f0f;
  82. color: #ff0;
  83. }
  84. #partFour {
  85. background: #ff0;
  86. color: #f00;
  87. }
  88. /*
  89. 伪元素选择器
  90. :first-child 第一个子元素
  91. :last-child 最后一个子元素
  92. :nth-child(xxx) 自定义子元素
  93. 偶数 even 2n
  94. 奇数 odd 2n+1
  95. */
  96. </style>
  97. </head>
  98. <body>
  99. <div>
  100. <h4>垂直导航</h4>
  101. <span>内容1</span><span>内容2</span><span>内容3</span>
  102. <ul>
  103. <li><a href="">首页</a></li>
  104. <li><a href="">我的</a></li>
  105. <li><a href="">购物车</a></li>
  106. <li><a href="">登录</a></li>
  107. </ul>
  108. <!-- 驼峰命名法:第二个单词首字母大写-->
  109. <div id="content">
  110. <div id="partOne">第一个盒子</div>
  111. <div id="part-two">第二个盒子</div>
  112. <div id="partThree">第三个盒子</div>
  113. <div id="partFour">第四个盒子</div>
  114. </div>
  115. </div>
  116. </body>
  117. </html>