文档页脚(VPDocFooter)的 Markdown 和 Edit 两个按钮没对齐,一高一低的。#1113
Open
endless-bot wants to merge 1 commit into
Open
Conversation
Generated by Endless task #27. Co-authored-by: Huacnlee Li Huashun <huacnlee@longbridge-inc.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Auto-generated by Endless task #27.
Initiated by: Huacnlee Li Huashun
背景
文档站(VitePress 2.0.0-alpha.16)每个文档页脚(
VPDocFooter)展示两个操作链接:左侧的 Markdown 下载链接(.llms-text-link)和右侧的 "Edit this page" 按钮(.edit-link-button)。两者应水平排列、垂直居中对齐,但实际渲染中出现高低错位的视觉 bug,影响所有语言版本的每个文档页面。该布局由自定义 CSS 控制:
.VPDocFooter被设置为 flex 容器(align-items: center),.edit-info通过display: contents将子元素"提升"为直接 flex 子项,使 Markdown 链接与 Edit 按钮同层排列并居中对齐。这一方案在设计上是正确的,但实际未能生效。根因
VitePress 2.0.0-alpha.16
VPDocFooter.vue的<style scoped>在 ≥640px 视口下会为.edit-info注入display: flex; padding-bottom: 14px,编译后的选择器为.edit-info[data-v-xxxx],CSS specificity =[0,2,0]。项目
index.css的覆写声明.VPDocFooter > .edit-info { display: contents }specificity 同为[0,2,0]。在相同 specificity 下,加载顺序靠后的声明胜出。VitePress 的 scoped 样式在 SSR 构建中可能晚于用户 CSS 注入,导致display: flex覆盖了display: contents。结果:
.edit-info保持display: flex并携带padding-bottom: 14px(总高 46px),其子元素.edit-link的垂直中心 = 距顶 16px;而.llms-text-link(line-height: 32px)作为兄弟 flex 子项在 46px 的容器空间中居中 = 距顶 23px。两者中心差 7px,呈现"一高一低"的视觉错位。摘要
docs/.vitepress/theme/style/index.css中为.VPDocFooter > .edit-info的display: contents声明添加!importantdisplay: contents的逻辑是正确的——只需确保它的优先级能稳定胜出 VitePress 的 scoped 样式;!important是最小侵入式的修复,无需改变选择器结构。.VPContent)"可行,但需要了解运行时的具体 scoped hash 才能构造稳定的反向覆写,维护成本更高。bun run dev,打开任意文档页(如/docs/getting-started)bun run build:canary构建后检查构建产物中同一页面的页脚渲染修改
docs/.vitepress/theme/style/index.css.VPDocFooter > .edit-info { display: contents }添加!important关键决策
使用
!important而非提升选择器 specificity:VitePress scoped 样式的data-v-xxxx哈希在每次构建时固定但对项目不透明,无法通过选择器覆写;!important是 CSS 规范提供的唯一与加载顺序无关的优先级机制,在此场景下语义清晰——"这个值必须被项目覆写,不受框架样式影响"。