CSS3 导航栏下划线跟随效果
作者:
Gino_Li | 来源:发表于
2019-04-14 14:19 被阅读0次<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
</title>
<style>
ul {
display: flex;
position: absolute;
width: 800px;
top: 30%;
left: 50%;
transform: translate(-50%, -50%);
}
li {
position: relative;
padding: 20px;
font-size: 24px;
color: #000;
line-height: 1;
transition: 1s all linear;
cursor: pointer;
list-style: none;
}
li::before {
content: "";
position: absolute;
top: 0;
left: 100%;
width: 0;
height: 100%;
border-bottom: 2px solid #000;
transition: 0.2s all linear;
}
li:hover::before {
width: 100%;
top: 0;
left: 0;
z-index: -1;
transition-delay: 0.1s;
}
li:hover~li::before {
left: 0;//关键,hover的时候其他兄弟元素li变0
}
</style>
</head>
<body>
<ul>
<li>首页</li>
<li>新闻</li>
<li>个人中心</li>
<li>关于我们</li>
<li>联系我们</li>
</ul>
</body>
</html>
本文标题:CSS3 导航栏下划线跟随效果
本文链接:https://www.haomeiwen.com/subject/prajwqtx.html
网友评论