今天给大家分享一个用CSS 3.0实现的悬停菜单特效,效果如下:
以下是代码实现,欢迎大家复制粘贴和收藏。
<!DOCTYPE html>标签:translateX,text,100%,transform,li,ul,3.0,悬停,CSS From: https://blog.51cto.com/u_15959833/6046798
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS 3.0实现的悬停菜单特效</title>
<style>
* {
font-family: '微软雅黑', sans-serif;
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #000;
overflow: hidden;
}
ul {
position: relative;
display: flex;
flex-direction: column;
}
ul li {
list-style: none;
transition: 0.5s;
}
ul li a {
position: relative;
color: transparent;
text-decoration: none;
font-weight: 900;
text-transform: uppercase;
letter-spacing: 2px;
font-size: 3em;
padding: 0 10px;
line-height: 1.2em;
}
ul li a::before {
content: attr(data-text);
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 0 10px;
-webkit-text-stroke: 1px #eee;
transform: translateX(0);
transition: 0.5s;
pointer-events: none;
}
ul li a:hover:before {
transform: translateX(100%);
opacity: 0;
}
ul li a::after {
content: attr(data-text);
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 0 10px;
transform: translateX(-100%);
transition: 0.5s;
pointer-events: none;
opacity: 0;
color: #03f4f2;
}
ul li a:hover:after {
transform: translateX(0);
opacity: 1;
}
</style>
</head>
<body>
<ul>
<li><a href="#" data-text="Home">Home</a></li>
<li><a href="#" data-text="About">About</a></li>
<li><a href="#" data-text="Services">Services</a></li>
<li><a href="#" data-text="Portfolio">Portfolio</a></li>
<li><a href="#" data-text="Team">Team</a></li>
<li><a href="#" data-text="Contact">Contact</a></li>
</ul>
</body>
</html>