Repository navigation
fix(sheet): 固定速查表页面左侧目录,滚动时目录不随页面滑走 - #14
Merged
Merged
Conversation
`html` and `body` both set `overflow-x: hidden`, which computes `overflow-y: auto` on `body` and turns it into a full-height scroll container. As a result, `position: sticky` on `.site-header` and `.doc-sidebar` stuck to `body` instead of the viewport, causing the left TOC (and header) to scroll out of view when navigating sections. - Replace `overflow-x: hidden` with `overflow-x: clip` on `html` and `body` so horizontal overflow stays clipped without breaking sticky positioning. - Align desktop `.doc-sidebar` `top` with `.doc-layout` top padding (`calc(var(--header-height) + 2rem)`), add `100dvh` max-height and `overscroll-behavior: contain`, and keep the active TOC link scrolled into view inside overflowing sidebars. - Increase mobile (`<= 900px`) `scroll-padding-top` so anchor jumps land below the restored sticky mobile TOC bar, and reset mobile sidebar `overflow-y` to `visible`. - Lock scrolling on `documentElement.style.overflowY` instead of `body.style.overflow` in `SearchModal`, and restore it immediately on close so sticky elements do not flicker and result jumps work smoothly.
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.
问题原因
src/styles/global.css在html和body上同时设置了overflow-x: hidden。按 CSS Overflow 规范,单轴设置hidden会让另一轴计算为auto,导致body变成一个与整页等高的滚动容器,从而破坏了.site-header和.doc-sidebar的position: sticky。点击左侧目录跳转或向下滚动时,整个页面与目录会一起向上滑出视口。改动内容
src/styles/global.csshtml与body的overflow-x: hidden替换为overflow-x: clip,在保持防止横向溢出的同时恢复position: sticky行为。.doc-sidebar的top对齐.doc-layout顶部内边距(calc(var(--header-height) + 2rem)),补充100dvh高度上限与overscroll-behavior: contain,避免初始滚动抖动和侧边栏滚动穿透。<= 900px)恢复顶部目录条吸顶后,提高scroll-padding-top至calc(var(--header-height) + 4.5rem),防止锚点标题被吸顶目录条遮挡;将.doc-sidebar的overflow-y还原为visible,为展开后的.toc-body.expanded增加overscroll-behavior: contain。src/components/SearchModal.astrodocument.documentElement.style.overflowY = 'hidden'并在关闭时立即恢复,避免通过body.style.overflow临时制造滚动容器导致吸顶导航/目录闪烁或影响搜索跳转滚动。src/layouts/Layout.astro验证结果
BASE_PATH=/)与子路径(BASE_PATH=/Codesheet)均通过npm run build && npm run check(22 个中英文页面、链接、锚点、OG、sitemap 全部通过)。1440×900(/python/)与较矮屏1280×720(/zh/cpp/):点击目录项(含最后一项)及通过搜索弹窗跳转后,顶部导航固定在top: 0、左侧目录固定在top: 96px,仅右侧速查表滚动。/cpp/):锚点跳转和目录固定均正常工作。390×844(/rust/)与375×667(/):无横向溢出,顶部导航与目录条吸顶,跳转标题完整露在目录条下方。sheets/*.md,未运行 sheet 示例检查器。