Skip to content

fix: preserve docs anchor offset#1282

Merged
Hmbown merged 1 commit intoHmbown:mainfrom
Wenjunyun123:fix-docs-anchor-offset
May 9, 2026
Merged

fix: preserve docs anchor offset#1282
Hmbown merged 1 commit intoHmbown:mainfrom
Wenjunyun123:fix-docs-anchor-offset

Conversation

@Wenjunyun123
Copy link
Copy Markdown
Contributor

@Wenjunyun123 Wenjunyun123 commented May 9, 2026

Why

Docs page section anchors used Tailwind scroll-mt-32 so headings should land below the sticky nav, but the global id selector in globals.css has the same specificity and loads later. That reduced the effective scroll margin to 5rem, leaving section titles partially hidden after sidebar anchor navigation.

Fixes #1278.

What changed

  • Lower the global anchor fallback specificity with :where([id]) so page-level Tailwind scroll-margin utilities can override it.
  • Keep the existing 5rem fallback for anchors that do not define their own offset.

Validation

  • git diff --check
  • Not run: npm run lint, because web/node_modules is not installed in this environment.

@Wenjunyun123 Wenjunyun123 marked this pull request as ready for review May 9, 2026 07:29
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the global CSS to use the :where() pseudo-class for the [id] selector's scroll-margin-top, which lowers its specificity to allow for easier overrides by page-level utilities. Feedback suggests that the hardcoded 5rem value may not be suitable for all screen sizes and recommends using CSS variables or media queries to handle responsive header heights more effectively.

Comment thread web/app/globals.css
/* Anchor scroll-margin so deep links land below the sticky nav. */
[id] { scroll-margin-top: 5rem; }
/* Anchor fallback; page-level scroll-mt utilities should be able to override it. */
:where([id]) { scroll-margin-top: 5rem; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The hardcoded 5rem value for scroll-margin-top is applied globally across all screen sizes. Given that the repository already defines responsive adjustments for other elements (e.g., the ticker at line 339), the sticky header height likely changes on smaller viewports. This could result in section titles being partially hidden or having excessive gaps on mobile. Consider using a CSS variable or a media query to adjust this offset for different breakpoints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs 页面侧边栏点击目录锚点链接(如 #modes、#tools)跳转后,目标 section 的顶部内容被 sticky nav header 遮挡

2 participants