网页技术交流
 
发新帖
楼主: 零五零八
查看: 817|回复: 0

[使用教程] CSS3实现菜单悬停效果

[复制链接]
零五零八 发表于 2021-1-28 21:31:30 | 显示全部楼层
html:


   
  1. <nav id="nav-1">
  2.   <a class="link-1" href="#">Home</a>
  3.   <a class="link-1" href="#">About</a>
  4.   <a class="link-1" href="#">Contact</a>
  5.   <a class="link-1" href="#">Shop</a>
  6. </nav>

  7. <nav id="nav-2">
  8.   <a class="link-2" href="#">Home</a>
  9.   <a class="link-2" href="#">About</a>
  10.   <a class="link-2" href="#">Contact</a>
  11.   <a class="link-2" href="#">Shop</a>
  12. </nav>

  13. <nav id="nav-3">
  14.   <a class="link-3" href="#">Home</a>
  15.   <a class="link-3" href="#">About</a>
  16.   <a class="link-3" href="#">Contact</a>
  17.   <a class="link-3" href="#">Shop</a>
  18. </nav>
复制代码

css:


  1. @import url(https://fonts.googleapis.com/css?family=Raleway);
  2. body {
  3.   margin: 0px;
  4. }
  5. nav {
  6.   margin-top: 40px;
  7.   padding: 24px;
  8.   text-align: center;
  9.   font-family: Raleway;
  10.   box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
  11. }
  12. #nav-1 {
  13.   background: #3fa46a;
  14. }
  15. #nav-2 {
  16.   background: #5175C0;
  17. }
  18. #nav-3 {
  19.   background: #EEA200;
  20. }

  21. .link-1 {
  22.   transition: 0.3s ease;
  23.   background: #3fa46a;
  24.   color: #ffffff;
  25.   font-size: 20px;
  26.   text-decoration: none;
  27.   border-top: 4px solid #3fa46a;
  28.   border-bottom: 4px solid #3fa46a;
  29.   padding: 20px 0;
  30.   margin: 0 20px;
  31. }
  32. .link-1:hover {
  33.   border-top: 4px solid #ffffff;
  34.   border-bottom: 4px solid #ffffff;
  35.   padding: 6px 0;
  36. }

  37. .link-2 {
  38.   transition: 0.6s;
  39.   color: #ffffff;
  40.   font-size: 20px;
  41.   text-decoration: none;
  42.   border-right: 2px dotted transparent;
  43.   padding: 30px 8px 0 10px;
  44.   margin: 0 10px;
  45. }
  46. .link-2:hover {
  47.   border-right: 2px dotted #ffffff;
  48.   padding-bottom: 24px;
  49. }
  50. .link-3 {
  51.   transition: 0.4s;
  52.   color: #ffffff;
  53.   font-size: 20px;
  54.   text-decoration: none;
  55.   padding: 0 10px;
  56.   margin: 0 10px;
  57. }
  58. .link-3:hover {
  59.   background-color: #ffffff;
  60.   color: #EEA200;
  61.   padding: 24px 10px;
  62. }
复制代码



快速回复 返回顶部 返回列表