console
<div class="container">
<nav class="nav">
<ul>
<li class="nav-item">
<a href="#" class="nav-item-a">前端样式</a>
<div class="nav-item-underline"></div>
</li>
</ul>
</nav>
<button id="btn" class="btn">切换样式</button>
</div>
* {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
body {
display: flex;
}
.container {
display: flex;
flex-direction: column;
width: 480px;
margin: 0 auto;
align-items: center;
background: rgba(0,0,0,.1);
}
.nav {
height: 80px;
line-height: 80px;
}
.nav-item {
position: relative;
width: 80px;
height: 60px;
text-align: center;
}
.nav-item .nav-item-underline {
position: absolute;
margin: 0 auto;
width: 0;
height: 2px;
bottom: 0;
background: blue;
transition: .5s all;
}
.nav-item>a {
display: block;
color: #000;
width: 100%;
height: 100%;
transition: .5s all;
}
.nav-item>a:hover {
color: blue;
}
.nav-item:hover>.nav-item-underline {
width: 100%;
}