From 6361ba484c6227fbcf7a401c41813a2b42a06436 Mon Sep 17 00:00:00 2001 From: bisnsh Date: Sun, 8 Feb 2026 19:03:16 +0800 Subject: [PATCH] fix nav --- .../butterfly/layout/includes/header/nav.pug | 21 ++-- themes/butterfly/source/css/nav.css | 96 +++++++++++++++++++ themes/butterfly/source/css/style.css | 63 ------------ 3 files changed, 107 insertions(+), 73 deletions(-) diff --git a/themes/butterfly/layout/includes/header/nav.pug b/themes/butterfly/layout/includes/header/nav.pug index 0180a26..d714471 100644 --- a/themes/butterfly/layout/includes/header/nav.pug +++ b/themes/butterfly/layout/includes/header/nav.pug @@ -1,4 +1,5 @@ nav#nav + //- 左侧区域:包含指纹菜单和网站名 span#blog-info #ls-menu-container i.fas.fa-fingerprint @@ -26,18 +27,18 @@ nav#nav img.site-icon(src=url_for(theme.nav.logo) alt='Logo') if theme.nav.display_title span.site-name=config.title - if globalPageType === 'post' && theme.nav.display_post_title - a.nav-page-title(href=url_for('/')) - span.site-name=(page.title || config.title) - span.site-name - i.fa-solid.fa-circle-arrow-left - span= ' ' + _p('post.back_to_home') - #menus - if theme.menu - != partial('includes/header/menu_item', {}, {cache: true}) - + //- 中间区域:关键!必须在 nav 下一级,以便 JS 切换类名 + if globalPageType === 'post' && theme.nav.display_post_title + a.nav-page-title(href='javascript:void(0);' onclick='btf.scrollToDest(0, 500)') + span.site-name=(page.title || config.title) + + //- 右侧区域 #nav-right + if theme.menu + #menus + != partial('includes/header/menu_item', {}, {cache: true}) + if theme.search.use || true #random-post-button a.site-page.social-icon#random-post-link(href='javascript:void(0);' onclick='randomPost()') diff --git a/themes/butterfly/source/css/nav.css b/themes/butterfly/source/css/nav.css index e9b5b93..d3cb705 100644 --- a/themes/butterfly/source/css/nav.css +++ b/themes/butterfly/source/css/nav.css @@ -1,3 +1,65 @@ + +#nav-right{ + flex:1 1 auto; + justify-content: flex-end; + margin-left: auto; + display: flex; + flex-wrap:nowrap; +} + +/* 导航栏居中 */ + +#sidebar #sidebar-menus .menus_items .menus_item { + margin: 10px 0; +} +#sidebar #sidebar-menus .menus_items a.site-page { + padding-left: 0; +} +#sidebar #sidebar-menus .menus_items .site-page { + position: relative; + display: block; + padding: 6px 30px 6px 22px; + color: var(--font-color); + font-size: 1.15em; + border: var(--style-border-always); + background: var(--icat-card-bg); + font-size: 14px; + border-radius: 12px; +} +#sidebar #sidebar-menus .menus_items .site-page i:first-child { + text-align: left; + padding-left: 10px; +} + +#nav #menus { + display: flex; + justify-content: center; + width: 100%; + position: absolute; + left: 0; + margin: 0; + transform: translateZ(0); +} +#nav #blog-info { + flex-wrap: nowrap; + display: flex; + align-items: center; + z-index: 102; + max-width: fit-content; +} +@media screen and (max-width: 900px) { + #nav { + padding: 0 15px; + } + #nav-group { + padding: 0 0.2rem; + } + #rightside { + right: -42px; + } +} +/* IPAD菜单栏调整 */ + /* 1. 容器溢出穿透 */ #nav, #blog-info, #nav-group { overflow: visible !important; @@ -112,4 +174,38 @@ [data-theme='dark'] .ls-grid a { color: #ccc !important; background: rgba(255, 255, 255, 0.05); +} + +/* --- 附加补丁:确保文章标题正常显示且居中 --- */ + +/* 1. 当文章标题显示类名触发时,确保它能浮现 */ +#nav.show-title .nav-page-title { + display: flex !important; + opacity: 1 !important; + visibility: visible !important; + /* 强制居中,不影响你原本的 blog-info 和 nav-right */ + position: absolute !important; + left: 50% !important; + transform: translateX(-50%) !important; + white-space: nowrap !important; + z-index: 1000 !important; /* 确保层级高于你原本的 menus */ +} + +/* 2. 滚动时自动隐藏原本占据 100% 宽度的菜单和站点标题,防止重叠 */ +#nav.show-title #menus, +#nav.show-title .nav-site-title { + opacity: 0 !important; + visibility: hidden !important; + pointer-events: none !important; +} + +/* 3. 修正文章标题的基础状态,防止它在页面顶端时乱入 */ +#nav .nav-page-title { + display: none; /* 默认隐藏,由 show-title 类名控制 */ + transition: opacity 0.3s ease; +} + +/* 4. 保持你原本 blog-info 的溢出显示,确保指纹菜单可用 */ +#nav #blog-info { + overflow: visible !important; } \ No newline at end of file diff --git a/themes/butterfly/source/css/style.css b/themes/butterfly/source/css/style.css index 5872058..9e23daa 100644 --- a/themes/butterfly/source/css/style.css +++ b/themes/butterfly/source/css/style.css @@ -364,69 +364,6 @@ background-size: cover; } -#nav-right{ - flex:1 1 auto; - justify-content: flex-end; - margin-left: auto; - display: flex; - flex-wrap:nowrap; -} - -/* 导航栏居中 */ - -#sidebar #sidebar-menus .menus_items .menus_item { - margin: 10px 0; -} -#sidebar #sidebar-menus .menus_items a.site-page { - padding-left: 0; -} -#sidebar #sidebar-menus .menus_items .site-page { - position: relative; - display: block; - padding: 6px 30px 6px 22px; - color: var(--font-color); - font-size: 1.15em; - border: var(--style-border-always); - background: var(--icat-card-bg); - font-size: 14px; - border-radius: 12px; -} -#sidebar #sidebar-menus .menus_items .site-page i:first-child { - text-align: left; - padding-left: 10px; -} - -#nav #menus { - display: flex; - justify-content: center; - width: 100%; - position: absolute; - left: 0; - margin: 0; - transform: translateZ(0); -} -#nav #blog-info { - flex-wrap: nowrap; - display: flex; - align-items: center; - z-index: 102; - max-width: fit-content; -} -@media screen and (max-width: 900px) { - #nav { - padding: 0 15px; - } - #nav-group { - padding: 0 0.2rem; - } - #rightside { - right: -42px; - } -} -/* IPAD菜单栏调整 */ - -/*https://codepen.io/poojanahelia/pen/Exabvdy*/ - #footer { background-color: rgba(0, 0, 0, 0); /* 修改透明色 */ color: #fff;