Skip to content

Commit 801ac0e

Browse files
committed
Fix scroll offset when jumping to internal id
1 parent e5e2b0b commit 801ac0e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/librustdoc/html/static/css/rustdoc.css

+8-1
Original file line numberDiff line numberDiff line change
@@ -1738,12 +1738,19 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17381738
}
17391739

17401740
@media (max-width: 700px) {
1741+
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,
1742+
or visiting a URL with a fragment like `#method.new`, we don't want the item to be obscured
1743+
by the topbar. Anything with an `id` gets scroll-margin-top equal to .mobile-topbar's size.
1744+
*/
1745+
*[id] {
1746+
scroll-margin-top: 45px;
1747+
}
1748+
17411749
.rustdoc {
17421750
padding-top: 0px;
17431751
/* Sidebar should overlay main content, rather than pushing main content to the right.
17441752
Turn off `display: flex` on the body element. */
17451753
display: block;
1746-
scroll-margin-top: 45px;
17471754
}
17481755

17491756
main {

src/test/rustdoc-gui/sidebar-mobile.goml

+6
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
2929

3030
// Check that the topbar is visible
3131
assert-property: (".mobile-topbar", {"clientHeight": "45"})
32+
33+
// Check that clicking an element from the sidebar scrolls to the right place
34+
// so the target is not obscured by the topbar.
35+
click: ".sidebar-menu-toggle"
36+
click: ".sidebar-links a"
37+
assert-position: ("#method\.must_use", {"y": 45})

0 commit comments

Comments
 (0)