菜单图标悬停效果 电脑版发表于:2021/5/28 11:23 tn>最近比较忙,写一篇好看的悬停效果散散心  ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="css/style.css"/> </head> <body> <nav class="nav"> <div class="menu"> <li class="item"> <a href="" class="link"> <i class="bi bi-house-fill"></i> </a> </li> <li class="item"> <a href="" class="link"> <i class="bi bi-emoji-smile"></i> <span>about</span> </a> </li> <li class="item"> <a href="" class="link"> <i class="bi bi-gear-wide"></i> <span>services</span> </a> </li> <li class="item"> <a href="" class="link"> <i class="bi bi-file-earmark-post"></i> <span>blog</span> </a> </li> <li class="item"> <a href="" class="link"> <i class="bi bi-envelope"></i> <span>contact</span> </a> </li> </div> </nav> </body> </html> ``` ```css @import url("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css"); *{ margin: 0; padding: 0; box-sizing: border-box; } html, body { height: 100%; } body{ display: flex; align-items: center; justify-content: center; } .nav{ display: flex; background-color: #4f48ec; height: 80px; border-radius: 16px; overflow: hidden; box-shadow: 0 8px 16px rgba(0,0,0,.15); } .nav .menu{ list-style: none; display: flex; justify-content: center; } .nav .menu .item { position: relative; cursor: pointer; padding: 0 10px; width: 150px; height: 150%; transition: ease .4s; } .nav .menu .item:hover{ background-color: #3932bf; } .nav .menu .item .link{ display: block; position: relative; width: 100%; height: 80px; color: #fff; text-transform: uppercase; text-decoration: none; overflow: hidden; transform: ease .4s; } .nav .menu .item .link span{ position: absolute; width: 100%; bottom: -50%; left: 0; text-align: center; opacity: 0; transition: ease .4s; } .nav .menu .item .link .bi{ position: absolute; top: 50%; left: 0; transform: translateY(-50%); width: 100%; text-align: center; font-size: 28px; transition: ease .4s; } .nav .menu .item:hover .link span{ opacity: 1; bottom: 10px; } .nav .menu .item:hover .link .bi{ transform: translateY(-75%); } ```