Use scroll-margin with floating navigation #7528
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes fragment links to use
scroll-margin-top
to offset their vertical scroll position when experienced alongside the floating navigation.This also changes the vertical offset from
75px
tocalc(64px + 0.5em)
. The64px
accounts for the height of the SubNav, which is computed frompx
units. The0.5em
accounts for the visual breathing room of the target itself, which is often text and thusly defined by itsem
size.Here are some examples of how the
px
andem
work best together:<li>
<h2>
<h3>
This change also updates the CSS selector used for this effect so that it applies to all active targets that appear after the SubNav. This allows non-link destinations like the Sidebar or "Edit this page" button to receive the same treatment, as well as any links that may not conform to the exact DOM tree presently required.
<a>
<a>
, best experienced with a small screenCoincidenting benefits
The use of the
:target
selector clearly communicates the intent of the rule while reducing the present complexity of the selector.The use of a
scroll-margin
property clearly communicates the intent of the declaration, while the removal of theposition
and its related styles reduce layout complexity.The
scroll-margin
property is not supported by Internet Explorer 11, which is a good thing because IE11 users do not experience the sticky navigation either. This prevents the unideal situation where an IE11 visitor is presented the wrong definition on a page, because the correct definition happens to be75px
below it.