<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.underline-navbar {
display: flex;
}
li {
position: relative;
padding: 10px;
cursor: pointer;
font-size: 20px;
color: #09f;
list-style: none;
}
li::before {
position: absolute;
left: 0;
top: 0;
border-bottom: 2px solid transparent;
width: 0;
height: 100%;
content: "";
transition: all 300ms 100ms;
}
li:active {
background-color: #09f;
color: #fff;
}
li:hover+li::before {
left: 0;
}
li:hover::before {
left: 0;
top: 0;
z-index: -1;
/* 颜色设置在hover这里:Hover时颜色渐显,消失时渐淡 。直接设置在li::before里没有这个效果*/
border-bottom-color: #09f;
width: 100%;
}
</style>
</head>
<body>
<div class="bruce flex-ct-x">
<ul class="underline-navbar">
<li>Alibaba阿里巴巴</li>
<li>Tencent腾讯</li>
<li>Baidu百度</li>
<li>Jingdong京东</li>
<li>Ant蚂蚁金服</li>
<li>Netease网易</li>
</ul>
</div>
</body>
</html>