代码块
更新时间: 8/31/2025, 1:51:17 PM
将代码组改成Mac风格,三个小圆点
在.vitepress/theme/style
目录新建一个vp-code.css
文件
md
.
├─ docs
│ ├─ .vitepress
│ │ └─ config.mts
│ │ └─ theme
│ │ └─ style
│ │ └─ index.css
│ │ └─ vp-code.css
│ └─ index.md
└─ node_modules
复制下面代码,粘贴到vp-code.css
保存
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
中引入生效
css
/* .vitepress/theme/style/index.css */
@import './vp-code.css';