Reverted scroll-margin-top solution for anchors due to poor Safari support

This commit is contained in:
squidfunk 2020-12-22 12:30:32 +01:00
parent 8320ca1675
commit f3ad7e2f28
9 changed files with 59 additions and 18 deletions

View File

@ -5,8 +5,8 @@
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.0ac82a11.min.js.map",
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.4ac00218.min.js",
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.4ac00218.min.js.map",
"assets/stylesheets/main.css": "assets/stylesheets/main.e86bb7d5.min.css",
"assets/stylesheets/main.css.map": "assets/stylesheets/main.e86bb7d5.min.css.map",
"assets/stylesheets/main.css": "assets/stylesheets/main.379d0e29.min.css",
"assets/stylesheets/main.css.map": "assets/stylesheets/main.379d0e29.min.css.map",
"assets/stylesheets/overrides.css": "assets/stylesheets/overrides.1a64f041.min.css",
"assets/stylesheets/overrides.css.map": "assets/stylesheets/overrides.1a64f041.min.css.map",
"assets/stylesheets/palette.css": "assets/stylesheets/palette.7cb87594.min.css",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -39,7 +39,7 @@
{% endif %}
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.e86bb7d5.min.css' | url }}">
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.379d0e29.min.css' | url }}">
{% if config.theme.palette %}
{% set palette = config.theme.palette %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.7cb87594.min.css' | url }}">

View File

@ -34,10 +34,18 @@
// Scoped in typesetted content to match specificity of regular content
.md-typeset {
// Footnote reference container - improve alignment
html & [id^="fnref:"] {
display: inline-block;
scroll-margin-top: px2rem(48px + 24px - 3px);
// Footnote reference
[id^="fnref:"]:target {
scroll-margin-top: initial;
margin-top: -1 * px2rem(48px + 24px - 4px);
padding-top: px2rem(48px + 24px - 4px);
}
// Footnote
[id^="fn:"]:target {
scroll-margin-top: initial;
margin-top: -1 * px2rem(48px + 24px - 3px);
padding-top: px2rem(48px + 24px - 3px);
}
// Footnote container

View File

@ -66,7 +66,10 @@
color: var(--md-accent-fg-color);
}
// Adjust scroll offset for all elements with `id` attributes
// Adjust scroll offset for all elements with `id` attributes - general scroll
// margin offset for anything that can be targeted. Browser support is pretty
// decent by now, but Edge <79 and Safari (iOS and macOS) still don't support
// it properly, so we settle with a cross-browser anchor correction solution.
:target {
scroll-margin-top: px2rem(48px + 24px);
}
@ -75,11 +78,41 @@
h1:target,
h2:target,
h3:target {
scroll-margin-top: px2rem(48px + 24px - 4px);
scroll-margin-top: initial;
// Anchor correction hack
&::before {
display: block;
margin-top: -1 * px2rem(48px + 24px - 4px);
padding-top: px2rem(48px + 24px - 4px);
content: "";
}
}
// Adjust scroll offset for headlines of level 4
h4:target {
scroll-margin-top: px2rem(48px + 24px - 3px);
scroll-margin-top: initial;
// Anchor correction hack
&::before {
display: block;
margin-top: -1 * px2rem(48px + 24px - 3px);
padding-top: px2rem(48px + 24px - 3px);
content: "";
}
}
// Adjust scroll offset for headlines of level 5-6
h5:target,
h6:target {
scroll-margin-top: initial;
// Anchor correction hack
&::before {
display: block;
margin-top: -1 * px2rem(48px + 24px);
padding-top: px2rem(48px + 24px);
content: "";
}
}
}

View File

@ -27,12 +27,12 @@
// Content area
.md-content {
flex-grow: 1;
// Hack: we must use `overflow: auto`, so the content area is capped by the
// dimensions of its parent. Otherwise, long code blocks might lead to a
// wider content area which will break everything. This, however, induces
// Hack: we must use `overflow: hidden`, so the content area is capped by
// the dimensions of its parent. Otherwise, long code blocks might lead to
// a wider content area which will break everything. This, however, induces
// margin collapse, which will break scroll margins. Adding a large enough
// scroll padding seems to do the trick, at least in Chrome and Firefox.
overflow: auto;
overflow: hidden;
scroll-padding-top: px2rem(1024px);
// Content wrapper