---
title: 添加网站左上角菜单
cover: https://pic.biss.click/image/a40baba1-b296-4b3b-a781-da45bffb1b95.webp
categories: 建站手札
series: webcustom
tags:
  - 网站
abbrlink: '7e921903'
summary: >-
  这篇文章详细介绍了如何在柳神的网站上添加一个自定义的左上角菜单，包括菜单的结构、样式以及响应式设计。作者提供了具体的HTML和CSS代码示例，展示了如何实现一个包含多个链接和功能的导航栏，同时确保在不同屏幕尺寸下的适配性。此外，还解释了一些关键的CSS属性和JavaScript交互效果，以实现平滑的菜单显示和隐藏。通过这些步骤，用户可以轻松地自定义和美化网站的顶部导航栏，提升用户体验。
date: 2026-02-10 07:11:14
---

{% note warning %}
注意：本文为早期 Hexo / Butterfly 魔改记录，本站现已迁移到 Astro，相关代码、路径或插件可能已经失效，仅作历史参考。
{% endnote %}

看到柳神的网站有这种菜单，但是没有写魔改教程，只好自己慢慢摸索了。

{% link liushen,liushen,https://blog.liushen.fun %}

预计做好后是这种效果：

![示意图](https://pic.biss.click/image/8d374eff-8817-4337-86ed-5909ff0eefaa.webp)

首先，修改```\themes\butterfly\layout\includes\header\nav.pug```:
```pug
nav#nav
  //- 左侧区域：包含指纹菜单和网站名
  span#blog-info
    #ls-menu-container
      i.fas.fa-fingerprint
      #ls-menu-panel
        .ls-section
          .ls-title 😀 个人网站
          .ls-grid
            a(href="/") #[i.fas.fa-rss] 个人博客
            a(href="https://github.com/bishshi") #[i.fab.fa-github] Github
        .ls-section
          .ls-title 😎 常用服务
          .ls-grid
            a(href="https://git.biss.click/biss") #[i.fas.fa-code] 代码仓库
            a(href="https://mm.biss.click") #[i.fas.fa-pen-nib] 日常yy
            a(href="https://statstic.biss.click") #[i.fas.fa-users] 访客统计
            a(href="https://pic.biss.click") #[i.fas.fa-image] 图床
            a(href="https://chat.biss.click") #[i.fas.fa-robot] AI网站
        .ls-section
          .ls-title 🛸 实用工具
          .ls-grid
            a(href="https://cover.biss.click") #[i.fas.fa-palette] 封面设计

    a.nav-site-title(href=url_for('/'))
      if theme.nav.logo
        img.site-icon(src=url_for(theme.nav.logo) alt='Logo')
      if theme.nav.display_title
        span.site-name=config.title

  //- 中间区域：关键！必须在 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()')
          i.fas.fa-solid.fa-shuffle
      #search-button
        a.site-page.social-icon.search-typesense-trigger
          i.fas.fa-search.fa-fw
      #toggle-menu
        span.site-page
          i.fas.fa-bars.fa-fw
```

在合适的目录下新建```nav.css```（例如```\themes\butterfly\source\css\nav.css```），这份css是磨砂玻璃的样式:

```css
#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;
}

#ls-menu-container {
  position: relative !important;
  display: inline-flex !important;
  align-items: center;
  height: 100%;
  padding: 0 15px;
  cursor: pointer !important;
  z-index: 2000 !important;
}

/* 2. 悬浮面板：宽大且高不透明度 */
#ls-menu-panel {
  position: absolute !important;
  top: 100% !important;
  left: 0 !important;
  margin-top: 15px !important;
  width: 420px; 
  padding: 24px;
  border-radius: 18px;
  
  /* 高不透明度磨砂玻璃 (0.9) */
  background: rgba(255, 255, 255, 0.95) !important;
  backdrop-filter: blur(20px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
  
  border: 1px solid rgba(255, 255, 255, 0.5) !important;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18) !important;

  opacity: 0 !important;
  visibility: hidden !important;
  transform: translateY(12px) !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  z-index: 999999 !important;
  cursor: default;
}

/* 3. 透明感应桥梁 */
#ls-menu-panel::before {
  content: "";
  position: absolute;
  top: -20px;
  left: 0;
  right: 0;
  height: 25px;
  background: transparent !important;
}

/* 4. 触发效果 */
#ls-menu-container:hover #ls-menu-panel {
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateY(0) !important;
}

#ls-menu-container:hover i.fa-fingerprint {
  color: #49b1f5;
  transform: scale(1.1);
}

/* 5. 内部网格：保持两列 */
.ls-section { margin-bottom: 22px; }
.ls-section:last-child { margin-bottom: 0; }
.ls-title { 
  color: #333; 
  font-weight: 800; 
  font-size: 15px; 
  margin-bottom: 12px; 
  opacity: 0.9;
}

.ls-grid { 
  display: grid !important; 
  grid-template-columns: repeat(2, 1fr); /* 恢复为两列 */
  gap: 10px; 
}

.ls-grid a { 
  color: #444 !important; 
  font-size: 14px !important; 
  padding: 10px 12px; 
  border-radius: 12px;
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
  background: rgba(0, 0, 0, 0.02);
}

.ls-grid a:hover { 
  background: #49b1f5 !important; 
  color: #fff !important; 
  transform: translateX(4px); /* 悬停时轻微右移，增加动感 */
}

.ls-grid a i { 
  margin-right: 12px; 
  width: 20px; 
  text-align: center; 
  font-size: 15px;
}

/* 6. 深色模式适配 */
[data-theme='dark'] #ls-menu-panel {
  background: rgba(30, 30, 30, 0.95) !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}
[data-theme='dark'] .ls-title { color: #eee; }
[data-theme='dark'] .ls-grid a { 
  color: #ccc !important; 
  background: rgba(255, 255, 255, 0.05); 
}

#nav.show-title .nav-page-title {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  position: absolute !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  white-space: nowrap !important;
  z-index: 1000 !important;
}

#nav.show-title #menus,
#nav.show-title .nav-site-title {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

#nav .nav-page-title {
  display: none; 
  transition: opacity 0.3s ease;
}

#nav #blog-info {
  overflow: visible !important;
}
```

然后在```_config.butterfly.yml```里面引用该css

```yml
- <link rel="stylesheet" href="/css/nav.css">
```

然后重新构建应该就可以看到效果了。