导航栏

HTML

1
2
3
4
5
6
7
8
<ul class="nav">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li class="underline"></li>
</ul>

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
.nav {
list-style-type: none;
position: relative;
padding: 0;
font-size: 0;
width: 750px;
height: 50px;
user-select: none;
overflow: hidden;
z-index: 10;
}
.nav li {
display: inline-block;
width: 20%;
height: 100%;
font-size: 18px;
line-height: 50px;
text-align: center;
cursor: pointer;
color: #666;
}
.nav .underline {
position: absolute;
width: 20%;
height: 3px;
background: #00ccff;
bottom: 3px;
left: 0;
z-index: -1;
transition: left .2s ease-in-out;
}
.nav li:nth-child(1):hover ~ .underline {
left: 0%;
}
.nav li:nth-child(2):hover ~ .underline {
left: 20%;
}
.nav li:nth-child(3):hover ~ .underline {
left: 40%;
}
.nav li:nth-child(4):hover ~ .underline {
left: 60%;
}
.nav li:nth-child(5):hover ~ .underline {
left: 80%;
}

最后更新: 2024年04月12日 02:45

原始链接: https://xiaguochang.github.io/posts/a295304e/