Mkdocs-material: Issue with custom anchor links (page jumps)

Created on 9 Jan 2017  路  11Comments  路  Source: squidfunk/mkdocs-material

Description

In order to add citation to my document I need to link the sentences to a footnote section (References). I tried to embed the html anchor tag in my markdown like this, However:

Expected behavior

I expect when I click the link:
1
It jumps exactly to the anchor point, like this in the default theme:
2

Actual behavior

However in material theme it lands a few line blew:
3

Steps to reproduce the bug

here is my index.md file used to produce above pictures:
index.txt
Define anchor point: <a id="cite_note-1"></a>
Link to anchor: [[1]](#cite_note-1)

Package versions

  • Python: Python 2.7.9
  • MkDocs: mkdocs, version 0.16.1
  • Material: Version: 0.2.4

System information

  • OS: Debian Gnu/Linux
  • Browser: Not relevant
bug

All 11 comments

Should be fixed in bfca02762d325324191beb8325e77360f5679cd6, please check and confirm.

Yes, now it works like a charm! :sparkles: :ok_hand:

Hi
I have this bug again with Footnotes extension.

I am still having this issue. If I add a custom anchor, when I click on the anchor, it scrolls just past the anchor. It appears as if it's scrolling to the correct location but not taking the height of the top header into account, so the header is covering up the anchor.

Any thoughts?

Custom anchors are currently not supported, as this could break stuff in unpredictable ways.

That's fine. Is there a way to only show the TOC on the sidebar for headers 1 and 2. Basically, if I use the anchors that the TOC generates, they work great. The problem is, for me to get anchors for header 3, I need to tell the TOC that I want 1-3, but that causes the sidebar to have 1-3 which is a mess. What I want is for all of the headers to have anchors, but the sidebar only show 1-2.

Please us the search on this and MkDocs's issue tracker. This was discussed in detail plenty of times.

Is there some sort of workaround to scroll up a bit when using custom anchors?

Here's a possible solution:

In the end I assigned class="cmnd" to each anchor I wanted this behaviour on and added to extra_css:

.cmnd:target {
    display: block;
    height: 4rem; /*approx same height as header*/
    margin-top: -4rem; /*approx same height as header*/
    visibility: hidden;
}

this will avoid unwanted effects if using globally

Jep, the side effects are the reason why this is not globally applied. Thanks for sharing your solution.

Was this page helpful?
0 / 5 - 0 ratings