Skip to content

Commit 435fdbd

Browse files
committed
style: 美化导航栏系统切换和主题切换按钮为现代滑块分段选择器
1 parent 1c5ad97 commit 435fdbd

1 file changed

Lines changed: 59 additions & 9 deletions

File tree

styles.css

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
--control-border: #c9d4e3;
4343
--control-active-bg: #17202e;
4444
--control-active-text: #f8fbff;
45+
--toggle-indicator-bg: #ffffff;
46+
--toggle-indicator-shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
4547
--focus-ring: rgba(37, 99, 235, 0.28);
4648
--danger: #c2410c;
4749
--danger-soft: #fff0e8;
@@ -85,6 +87,8 @@
8587
--control-border: #30465d;
8688
--control-active-bg: #e6edf8;
8789
--control-active-text: #10213a;
90+
--toggle-indicator-bg: #223147;
91+
--toggle-indicator-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.06);
8892
--focus-ring: rgba(125, 171, 255, 0.32);
8993
--danger: #ff9a73;
9094
--danger-soft: #3a2118;
@@ -127,6 +131,8 @@
127131
--control-border: #30465d;
128132
--control-active-bg: #e6edf8;
129133
--control-active-text: #10213a;
134+
--toggle-indicator-bg: #223147;
135+
--toggle-indicator-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.06);
130136
--focus-ring: rgba(125, 171, 255, 0.32);
131137
--danger: #ff9a73;
132138
--danger-soft: #3a2118;
@@ -334,13 +340,36 @@ a,
334340

335341
.os-toggle,
336342
.theme-toggle {
343+
position: relative;
337344
display: inline-flex;
338345
align-items: center;
339-
gap: 0.25rem;
340346
padding: 0.2rem;
341347
border: 1px solid var(--control-border);
342348
border-radius: 999px;
343349
background: var(--control-bg);
350+
isolation: isolate;
351+
}
352+
353+
/* 滑块指示器 */
354+
.os-toggle::before,
355+
.theme-toggle::before {
356+
content: "";
357+
position: absolute;
358+
top: 0.2rem;
359+
bottom: 0.2rem;
360+
left: 0.2rem;
361+
width: calc(50% - 0.2rem);
362+
background: var(--toggle-indicator-bg);
363+
border-radius: 999px;
364+
box-shadow: var(--toggle-indicator-shadow);
365+
transition: transform 0.28s cubic-bezier(0.25, 1, 0.5, 1);
366+
z-index: 1;
367+
}
368+
369+
/* 滑动位移 */
370+
.os-toggle:has([data-os="win"].active)::before,
371+
.theme-toggle:has([data-theme="dark"].active)::before {
372+
transform: translateX(100%);
344373
}
345374

346375
.os-btn,
@@ -351,19 +380,32 @@ a,
351380
color: var(--text-soft);
352381
font: inherit;
353382
cursor: pointer;
354-
}
355-
356-
.os-btn,
357-
.theme-btn {
358383
min-height: 44px;
359-
min-width: 44px;
360384
padding: 0.6rem 0.95rem;
361385
border-radius: 999px;
362386
display: inline-flex;
363387
align-items: center;
364388
justify-content: center;
365389
gap: 0.4rem;
366-
transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
390+
position: relative;
391+
z-index: 2;
392+
flex: 1;
393+
transition: color 0.2s ease, transform 0.1s ease;
394+
}
395+
396+
.os-btn {
397+
min-width: 4.8rem;
398+
}
399+
400+
.theme-btn {
401+
min-width: 3.2rem;
402+
font-weight: 700;
403+
}
404+
405+
/* 按钮点击缩放反馈 */
406+
.os-btn:active,
407+
.theme-btn:active {
408+
transform: scale(0.95);
367409
}
368410

369411
.github-star-link {
@@ -426,14 +468,21 @@ a,
426468
}
427469

428470
.os-btn.active,
429-
.theme-btn.active,
471+
.theme-btn.active {
472+
color: var(--text);
473+
font-weight: 800;
474+
}
475+
430476
.section-switcher-btn.active {
431477
background: var(--control-active-bg);
432478
color: var(--control-active-text);
433479
}
434480

435481
.os-btn:hover:not(.active),
436-
.theme-btn:hover:not(.active),
482+
.theme-btn:hover:not(.active) {
483+
color: var(--text);
484+
}
485+
437486
.section-switcher-btn:hover:not(.active) {
438487
background: color-mix(in srgb, var(--panel) 60%, var(--control-bg));
439488
}
@@ -1137,6 +1186,7 @@ a,
11371186
min-height: 38px;
11381187
padding: 0.48rem 0.72rem;
11391188
flex: 1;
1189+
min-width: 0;
11401190
}
11411191

11421192
.github-star-link {

0 commit comments

Comments
 (0)