Skip to content

Fix #id targets landing under the sticky header - #2775

Merged
claudiacodacy merged 1 commit into
masterfrom
fix-anchor-scroll-offset
Oct 6, 2026
Merged

claudiacodacy merged 1 commit into
masterfrom
fix-anchor-scroll-offset

Conversation

@claudiacodacy

Copy link
Copy Markdown
Contributor

Problem

Opening a page with a #id in the URL often leaves the target hidden under the navbar (reported by Ioan in Slack). Example: /codacy-ai/codacy-ai/#ai-features put the heading at 93px while the header is 109px tall.

Cause

  • scroll-margin-top on headings was 5rem (80px), but the desktop header is ~109px because the tabs row is part of it.
  • The rule only covered h1–h6, so other #id targets got no offset.

Change

  • theme/stylesheets/content.css: apply scroll-margin-top to .md-typeset [id]: 5rem below 76.25em (header ~61px), 8rem from 76.25em (header ~109px). Both leave ~19px of clearance.
  • theme/stylesheets/base.css: update the comment that referred to headings only.
  • Still no page-wide scroll-padding-top on <html>, per the existing comment (it caused a scroll jump when opening search).

Verified

Injected the same CSS into docs.codacy.com at 1280px and 600px wide on /codacy-ai/codacy-ai/#ai-features: 19px clearance at both widths.

Not verified

  • mkdocs build --strict (submodules not initialised in my worktree)
  • Light vs. dark scheme separately (no colour changes)
  • A non-heading #id target
  • Navigation between pages

🤖 Generated with Claude Code

The scroll-margin-top on headings was 5rem (80px) but the desktop header
is ~109px with the tabs row, so anchored headings were overlapped. The
rule also only covered h1-h6, leaving other #id targets with no offset.

Apply the offset to any [id] in .md-typeset: 5rem below 76.25em (header
~61px) and 8rem from 76.25em (header ~109px).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@claudiacodacy
claudiacodacy requested a review from a team as a code owner October 6, 2026 08:24
@codacy-production

Copy link
Copy Markdown
Contributor

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

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.

Pull Request Overview

No merge-blocking security or logic issues were identified. Codacy reports the PR is up to standards. The requested behavior should still be covered by automated tests, particularly for responsive heading and non-heading anchors and focus/search behavior.

About this PR

  • No automated tests are included for the responsive anchor offsets, non-heading targets, or focus/search behavior. Add coverage for these scenarios before relying on the change.

Test suggestions

  • Verify heading anchor targets remain visible below the sticky header below 76.25em.
  • Verify heading anchor targets remain visible below the sticky header at or above 76.25em.
  • Verify non-heading elements with IDs receive the same responsive offset.
  • Verify search or focus behavior is not adversely affected by page-wide scroll padding.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify heading anchor targets remain visible below the sticky header below 76.25em.
2. Verify heading anchor targets remain visible below the sticky header at or above 76.25em.
3. Verify non-heading elements with IDs receive the same responsive offset.
4. Verify search or focus behavior is not adversely affected by page-wide scroll padding.
Low confidence findings
  • The PR does not report a successful strict build; verify the build in an environment with initialized submodules before merging.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

@github-actions
github-actions Bot temporarily deployed to Netlify October 6, 2026 08:26 Inactive
@claudiacodacy
claudiacodacy enabled auto-merge (squash) October 6, 2026 08:26
@claudiacodacy
claudiacodacy merged commit bb4e79e into master Oct 6, 2026
5 checks passed
@claudiacodacy
claudiacodacy deleted the fix-anchor-scroll-offset branch October 6, 2026 08:36

This branch was previously deployed

1 inactive deployment
Netlify — bd716caf Deployed Oct 6, 2026 by github-actions[bot]
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.

2 participants