#

代码块

By DoubleSpirit121 1 Views 5 MIN READ 0 Comments
将代码块样式改为 Mac 风格,添加红绿黄三色窗口按钮。通过 CSS 样式覆盖,将 VitePress 的代码块顶部添加 Mac 系统的红绿黄三色圆形按钮,模拟 Mac 窗口外观,提升代码展示区域的视觉效果。

将代码组改成Mac风格,三个小圆点

.vitepress/theme/style目录新建一个vp-code.css文件

.
├─ docs
│  ├─ .vitepress
│  │  └─ config.mts
│  │  └─ theme
│  │     └─ style
│  │        └─ index.css
│  │        └─ vp-code.css
│  └─ index.md
└─ node_modules

复制下面代码,粘贴到vp-code.css保存

/* .vitepress/theme/style/vp-code.css */

/* 代码块:增加留空边距 增加阴影 */
.vp-doc div[class*=language-] {
  box-shadow: 0 10px 30px 0 rgb(0 0 0 / 40%);
  padding-top: 20px;
}

/* 代码块:添加macOS风格的小圆点 */
.vp-doc div[class*=language-]::before {
  content: "";
  display: block;
  position: absolute;
  top: 12px;
  left: 12px;
  width: 12px;
  height: 12px;
  background-color: #ff5f56;
  border-radius: 50%;
  box-shadow: 20px 0 0 #ffbd2e, 40px 0 0 #27c93f;
  z-index: 1;
}

/* 代码块:下移行号 隐藏右侧竖线 */
.vp-doc .line-numbers-wrapper {
  padding-top: 40px;
  border-right: none;
}

/* 代码块:重建行号右侧竖线 */
.vp-doc .line-numbers-wrapper::after {
  content: "";
  position: absolute;
  top: 40px;
  right: 0;
  border-right: 1px solid var(--vp-code-block-divider-color);
  height: calc(100% - 60px);
}

.vp-doc div[class*='language-'].line-numbers-mode {
  margin-bottom: 20px;
}

然后在index.css中引入生效

/* .vitepress/theme/style/index.css */
@import './vp-code.css';

本文由 DoubleSpirit121 原创

采用 CC BY-NC-SA 4.0 协议进行许可

转载请注明出处:https://blog.mcoo.top/index.php/archives/29/

加入 Mcoo

0 评论

发表评论