|
3 | 3 | --- |
4 | 4 |
|
5 | 5 | <nav class="menu"> |
6 | | - <a href="/" data-astro-prefetch>Ling的小窝</a> |
7 | | - <a href="/blog" data-astro-prefetch>博客</a> |
8 | | - <a href="/time-line" data-astro-prefetch>时线</a> |
9 | | - <a href="/lab" data-astro-prefetch>实验</a> |
10 | | - <a href="/friend-links" data-astro-prefetch>友链</a> |
11 | | - <a href="/about" data-astro-prefetch>关于</a> |
| 6 | + <a id="index" href="/" data-astro-prefetch>Ling的小窝</a> |
| 7 | + <a id="blog" href="/blog" data-astro-prefetch>博客</a> |
| 8 | + <a id="time-line" href="/time-line" data-astro-prefetch>时线</a> |
| 9 | + <a id="lab" href="/lab" data-astro-prefetch>实验</a> |
| 10 | + <a id="friend-links" href="/friend-links" data-astro-prefetch>友链</a> |
| 11 | + <a id="about" href="/about" data-astro-prefetch>关于</a> |
12 | 12 | </nav> |
13 | 13 |
|
| 14 | +<script> |
| 15 | + const updateSelected = () => { |
| 16 | + let pathname = window.location.pathname.substring(1); |
| 17 | + pathname = pathname === "" ? "index" : pathname; |
| 18 | + const e = document.getElementById(pathname); |
| 19 | + if (!e) { |
| 20 | + return; |
| 21 | + } |
| 22 | + e.classList.add("selected"); |
| 23 | + }; |
| 24 | + updateSelected(); |
| 25 | +</script> |
| 26 | + |
14 | 27 | <style> |
15 | 28 | .menu { |
16 | 29 | display: flex; |
17 | 30 | align-items: center; |
18 | 31 | justify-content: space-around; |
19 | 32 | width: 600px; |
20 | 33 | height: 55px; |
21 | | - |
22 | | - background-color: white; |
23 | | - border: 2px solid black; /* 添加黑色的边框,宽度为 2px */ |
| 34 | + background-color: rgba(255, 255, 255, 0.1); |
| 35 | + backdrop-filter: blur(4px); |
| 36 | + border: 1px solid rgba(0, 0, 0, 0.2); /* 添加黑色的边框,宽度为 2px */ |
24 | 37 | border-radius: 40px; |
25 | 38 | padding: 0 25px; /* 给容器添加左右内边距 */ |
26 | 39 | } |
27 | 40 |
|
28 | 41 | .menu > a { |
29 | | - color: black; /* 文字颜色 */ |
| 42 | + color: rgba(0, 0, 0, 0.7); /* 文字颜色 */ |
30 | 43 | padding: 7px 15px; /* 内边距 */ |
31 | 44 | text-decoration: none; /* 去除下划线 */ |
32 | 45 | border-radius: 18px; /* 圆角 */ |
33 | 46 | font-size: 19px; /* 字体大小 */ |
| 47 | + transition: |
| 48 | + background-color 0.2s ease-in-out, |
| 49 | + color 0.2s ease-in-out; |
34 | 50 | } |
35 | 51 |
|
36 | 52 | .menu > a:hover { |
37 | | - background-color: #dddddd; |
38 | | - transition: background-color 0.2s ease-in-out; |
| 53 | + background-color: rgba(221, 221, 221, 0.4); |
| 54 | + } |
| 55 | + |
| 56 | + .menu > a.selected { |
| 57 | + transition: none; |
| 58 | + background-color: rgba(0, 0, 0, 0.5); |
| 59 | + color: rgba(247, 247, 249, 1); |
| 60 | + } |
| 61 | + |
| 62 | + .menu > a.selected:hover { |
| 63 | + transition:none; |
| 64 | + background-color: rgba(0, 0, 0, 0.6); |
| 65 | + color: rgba(247, 247, 249, 1); |
39 | 66 | } |
40 | 67 | </style> |
0 commit comments