diff options
| author | Jacob Hoffman-Andrews <github@hoffman-andrews.com> | 2022-01-18 22:05:17 -0800 |
|---|---|---|
| committer | Jacob Hoffman-Andrews <github@hoffman-andrews.com> | 2022-01-19 12:45:16 -0800 |
| commit | 801ac0e24ff6269fe71d22d29b8482e2117b2f82 (patch) | |
| tree | c7cf64d1ae73ab13367d82608b497de4b429c8fd /src | |
| parent | e5e2b0be26ea177527b60d355bd8f56cd473bd00 (diff) | |
| download | rust-801ac0e24ff6269fe71d22d29b8482e2117b2f82.tar.gz rust-801ac0e24ff6269fe71d22d29b8482e2117b2f82.zip | |
Fix scroll offset when jumping to internal id
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/html/static/css/rustdoc.css | 9 | ||||
| -rw-r--r-- | src/test/rustdoc-gui/sidebar-mobile.goml | 6 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index dbc068ce6b1..947eb5a37f2 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1738,12 +1738,19 @@ details.rustdoc-toggle[open] > summary.hideme::after { } @media (max-width: 700px) { + /* When linking to an item with an `id` (for instance, by clicking a link in the sidebar, + or visiting a URL with a fragment like `#method.new`, we don't want the item to be obscured + by the topbar. Anything with an `id` gets scroll-margin-top equal to .mobile-topbar's size. + */ + *[id] { + scroll-margin-top: 45px; + } + .rustdoc { padding-top: 0px; /* Sidebar should overlay main content, rather than pushing main content to the right. Turn off `display: flex` on the body element. */ display: block; - scroll-margin-top: 45px; } main { diff --git a/src/test/rustdoc-gui/sidebar-mobile.goml b/src/test/rustdoc-gui/sidebar-mobile.goml index 547eb3fd1b3..680822b6ecb 100644 --- a/src/test/rustdoc-gui/sidebar-mobile.goml +++ b/src/test/rustdoc-gui/sidebar-mobile.goml @@ -29,3 +29,9 @@ assert-css: (".sidebar", {"display": "block", "left": "-1000px"}) // Check that the topbar is visible assert-property: (".mobile-topbar", {"clientHeight": "45"}) + +// Check that clicking an element from the sidebar scrolls to the right place +// so the target is not obscured by the topbar. +click: ".sidebar-menu-toggle" +click: ".sidebar-links a" +assert-position: ("#method\.must_use", {"y": 45}) |
