<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS3鼠标悬停图标导航动画</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Arial', sans-serif;
}
body {
background: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.nav-container {
display: flex;
background: #fff;
padding: 20px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}
.nav-item {
position: relative;
width: 70px;
height: 70px;
margin: 0 10px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.nav-item i {
font-size: 30px;
color: #333;
transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.nav-item .tooltip {
position: absolute;
top: 0;
background: #fff;
color: #fff;
padding: 5px 10px;
border-radius: 5px;
font-size: 14px;
opacity: 0;
pointer-events: none;
transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}
.nav-item:hover {
transform: translateY(-10px);
}
.nav-item:hover i {
color: #fff;
}
.nav-item:hover .tooltip {
top: -45px;
opacity: 1;
}
/* 不同图标的颜色 */
.nav-item:nth-child(1):hover,
.nav-item:nth-child(1) .tooltip {
background: #4267B2; /* Facebook蓝 */
}
.nav-item:nth-child(2):hover,
.nav-item:nth-child(2) .tooltip {
background: #1DA1F2; /* Twitter蓝 */
}
.nav-item:nth-child(3):hover,
.nav-item:nth-child(3) .tooltip {
background: #E1306C; /* Instagram粉 */
}
.nav-item:nth-child(4):hover,
.nav-item:nth-child(4) .tooltip {
background: #FF0000; /* YouTube红 */
}
.nav-item:nth-child(5):hover,
.nav-item:nth-child(5) .tooltip {
background: #0e76a8; /* LinkedIn蓝 */
}
.website-link {
position: fixed;
bottom: 20px;
color: #666;
font-size: 14px;
}
.website-link a {
color: #4267B2;
text-decoration: none;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>
<body>
<div class="nav-container">
<div class="nav-item">
<i class="fab fa-facebook-f"></i>
<span class="tooltip">Facebook</span>
</div>
<div class="nav-item">
<i class="fab fa-twitter"></i>
<span class="tooltip">Twitter</span>
</div>
<div class="nav-item">
<i class="fab fa-instagram"></i>
<span class="tooltip">Instagram</span>
</div>
<div class="nav-item">
<i class="fab fa-youtube"></i>
<span class="tooltip">YouTube</span>
</div>
<div class="nav-item">
<i class="fab fa-linkedin-in"></i>
<span class="tooltip">LinkedIn</span>
</div>
</div>
</body>
</html>
CSS3鼠标悬停图标导航动画
于 2025-05-06 14:48:22 首次发布