当前位置:   article > 正文

3、css3 手写nav导航条(互相学习)

3、css3 手写nav导航条(互相学习)

效果例图:

1、首先呈现的是html代码:

  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link rel="stylesheet" href="./3.css">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <nav class="navbar">
  11. <ul class="nav-list">
  12. <li class="nav-item">
  13. <a href="#" class="nav-link">home</a></li>
  14. <li class="nav-item">
  15. <a href="#" class="nav-link">about</a>
  16. <ul class="dropdown">
  17. <li class="dropdown-item"><a href="#" class="dropdown-link">Our Team</a></li>
  18. <li class="dropdown-item"><a href="#" class="dropdown-link">Our Story</a></li>
  19. <li class="dropdown-item"><a href="#" class="dropdown-link">Careers</a></li>
  20. </ul>
  21. </li>
  22. <li class="nav-item">
  23. <a href="#" class="nav-link">Services</a>
  24. <ul class="dropdown">
  25. <li class="dropdown-item"><a href="#" class="dropdown-link">web</a></li>
  26. <li class="dropdown-item"><a href="#" class="dropdown-link">html</a></li>
  27. <li class="dropdown-item"><a href="#" class="dropdown-link">dockewr</a></li>
  28. <li class="dropdown-item"><a href="#" class="dropdown-link">nginx</a></li>
  29. <li class="dropdown-item"><a href="#" class="dropdown-link">hahah</a></li>
  30. </ul>
  31. </li>
  32. <li class="nav-item">
  33. <a href="#" class="nav-link">Contact</a>
  34. </li>
  35. </ul>
  36. </nav>
  37. </body>
  38. </html>

 2、其次最关键的css3样式代码:

  1. body{
  2. margin: 0;
  3. font-family: Arial, Helvetica, sans-serif;
  4. background-color: #f0f0f0;
  5. display: flex;
  6. justify-content: center;
  7. align-items: center;
  8. min-height: 100vh;
  9. }
  10. .navbar{
  11. background-color: #333;
  12. width: 100%;
  13. position: fixed;
  14. top: 0;
  15. left: 0;
  16. }
  17. .nav-list{
  18. list-style: none;
  19. margin: 0;
  20. padding: 0;
  21. display: flex;
  22. justify-content: center;
  23. }
  24. .nav-item{
  25. position: relative;
  26. }
  27. .nav-link{
  28. display: block;
  29. padding: 15px 20px;
  30. color: white;
  31. text-decoration: none;
  32. font-size: 18px;
  33. transition: background-color 0.3s,transform 0.3s;
  34. position: relative;
  35. z-index: 1;
  36. }
  37. .nav-link:hover{
  38. background-color: #008c8c;
  39. transform: scale(1.1);
  40. }
  41. .nav-link::after{
  42. content: "";
  43. position: absolute;
  44. left: 50%;
  45. width: 0;
  46. height: 3px;
  47. background-color: #f8f400;
  48. transition: all 0.4s;
  49. bottom: 0;
  50. z-index: 1;
  51. }
  52. .nav-link:hover::after{
  53. left: 0;
  54. width: 100%;
  55. }
  56. .dropdown{
  57. display: none;
  58. /* height: 0px; */
  59. position: absolute;
  60. top: calc(100% + 2px);
  61. left: -5px;
  62. background-color: #444;
  63. list-style: none;
  64. margin: 0;
  65. padding: 0;
  66. overflow: hidden;
  67. border-radius: 3px;
  68. min-width: 150px;
  69. z-index: 1000;
  70. opacity: 0;
  71. transform: translateY(-10px);
  72. transition: background-color 0.6s ease-in-out;
  73. }
  74. .dropdown-item{
  75. position: relative;
  76. }
  77. .dropdown-link{
  78. display: block;
  79. padding: 15px 20px;
  80. color: white;
  81. text-decoration: none;
  82. font-size: 18px;
  83. transition: background-color 0.3s;
  84. }
  85. .dropdown-link::after{
  86. content: "";
  87. position: absolute;
  88. bottom: 0;
  89. left: 50%;
  90. width: 0px;
  91. height: 2px;
  92. transition: all 0.4s ease-in-out;
  93. }
  94. .dropdown-link:hover{
  95. background-color: #008c8c;
  96. }
  97. .dropdown-link:hover::after{
  98. left: 0;
  99. width: 100%;
  100. background-color: #f8f400;
  101. }
  102. .nav-item:hover .dropdown{
  103. display: block;
  104. /* height: 300px; */
  105. opacity: 1;
  106. transform: translateY(0);
  107. }

总结:CSS太强大了,只是我们现在的学习知识不够,不能够很好的驾驭它,

活到老学到老

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号