Skip to content

Safari bug: anchor links stay behind the navbar #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
12rambau opened this issue Mar 1, 2021 · 9 comments
Closed

Safari bug: anchor links stay behind the navbar #325

12rambau opened this issue Mar 1, 2021 · 9 comments

Comments

@12rambau
Copy link
Collaborator

12rambau commented Mar 1, 2021

When I type a search in my search bar like for example NumberField in https://sepal-ui.readthedocs.io/en/latest/index.html

and select one of the found anchor (https://sepal-ui.readthedocs.io/en/latest/modules/sepal_ui.sepalwidgets.html?highlight=NumberField#sepal_ui.sepalwidgets.inputs.NumberField) the anchor is placed behind the navbar. Is it possible to add extra padding to the js script ?

It appears this way :

Capture d’écran 2021-03-01 à 14 42 30

And it would be more useful
Capture d’écran 2021-03-01 à 14 43 28
this way :

@jorisvandenbossche
Copy link
Member

@12rambau
Copy link
Collaborator Author

12rambau commented Mar 1, 2021

For both of them the title was hidden behind the navbar.

As we are entering the horrible zone of device compatibility I use :
MacOS BigSur 11.1
Safari 14.0.2

It works on Firefox 84.0.2 on the latest doc

@jorisvandenbossche
Copy link
Member

Hmm. I was using firefox, so there indeed in now works (and didn't work for the stable release). For Chrome it seems to work as well (at least on Ubuntu).

The latest version is using scroll-padding-top for this (#318), and https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding-top indicates that Safari only has partial support, so that's probably the reason.

For Safari we could maybe keep what was removed in #318 as fallback? (that should work for at least most links)

@drammock
Copy link
Collaborator

drammock commented Mar 1, 2021

Unfortunately it is a known bug that Safari doesn't (yet) support the CSS property that we're using to handle this:

https://bugs.webkit.org/show_bug.cgi?id=179379

@drammock
Copy link
Collaborator

drammock commented Mar 1, 2021

Using something like

// offsetting html elements with anchor attached to adjust for fixed header
:target {
  &::before {
    // offsetting html anchor titles to adjust for fixed header
    display: block;
    content: '';
    height: var(--header-height);
    margin: calc(-1 * var(--header-height)) 0 0;
    background-color: white;
  }
}

as @jorisvandenbossche suggests would probably work for your specific example, @12rambau, but you should know that it has a drawback: any inline anchors that are targeted (i.e., a mid-sentence citation that is the target of a backreference) will be quite badly broken (they willl break the line, and if they have :before content like a parenthesis or bracket, these will get moved up by the margin amount).

Personally I would hesitate to re-incorporate that behavior into the theme; I think the failure to scroll on safari is less bad than the side-effect for inline targets that I just described... I would recommend individual users to add the above to their site's CSS if (1) they know they won't have any inline target anchors, or (2) they think the scrolling problem is too painful and are willing to accept the breakage to the inline target anchors.

@12rambau
Copy link
Collaborator Author

12rambau commented Mar 1, 2021

I think this is a very minor problem. I agree that breaking inline anchor is a big risk and if it's only to save a bug from Safari it's not worth it.

I will let the issue open until a new workaround emerge OR the bug solve itself with a update of safari

@jorisvandenbossche
Copy link
Member

Indeed, probaby best to keep it as is in the theme. Now, if you know as a downstream user that you don't have any inline anchors, you can still put the above css snippet in your custom.css.

@jorisvandenbossche jorisvandenbossche changed the title when using the search bar the anchor stays behind the navbar Safari bug: anchor links stay behind the navbar Mar 1, 2021
@pradyunsg
Copy link
Contributor

scroll-padding-top
a known bug that Safari doesn't (yet) support the CSS property that we're using to handle this:

FWIW, the workaround is to use scroll-margin-top. 😉

I first noticed this in https://github.com/squidfunk/mkdocs-material/blob/714a9cc7d1e33b250753c722d87d54cdabc39d3d/docs/changelog.md#516-_-may-9-2020, and this is what Furo does:

https://github.com/pradyunsg/furo/blob/be3efbd3649db0b261dca781d43717442663df51/src/furo/assets/styles/_scaffold.sass#L280-L282

@12rambau
Copy link
Collaborator Author

It seems that the bug is now solved from Safari's side. (At least it's not an issue on my docs any more)

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

No branches or pull requests

4 participants