Skip to content

Commit 3924493

Browse files
committed
rustdoc: make sidebar highlight cover whole click target
1 parent 5fc30b8 commit 3924493

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ ul.block, .block li {
564564
/* extend click target to far edge of screen (mile wide bar) */
565565
border-left: solid var(--sidebar-elems-left-padding) transparent;
566566
margin-left: calc(-0.25rem - var(--sidebar-elems-left-padding));
567-
background-clip: padding-box;
567+
background-clip: border-box;
568568
}
569569

570570
.sidebar h2 {
@@ -641,11 +641,50 @@ ul.block, .block li {
641641
text-align: center;
642642
}
643643

644+
.sidebar-crate .logo-container img {
645+
/* When in a horizontal logo lockup, the highlight color of the crate name menu item
646+
extends underneath the actual logo (in a vertical lockup, that background highlight
647+
extends to the left edge of the screen).
648+
649+
To prevent a weird-looking colored band from appearing under the logo, cover it up
650+
with the sidebar's background. Additionally, the crate name extends slightly above
651+
the logo, so that its highlight has a bit of space to let the ascenders breath while
652+
also having those ascenders meet exactly with the top of the logo.
653+
654+
In ANSI art, make it look like this:
655+
| ┌─────┐
656+
| (R) │ std │
657+
| └─────┘
658+
659+
Not like this (which would happen without the z-index):
660+
| ┌────────┐
661+
| (│ std │
662+
| └────────┘
663+
664+
Not like this (which would happen without the background):
665+
| ┌────────┐
666+
| (R) std │
667+
| └────────┘
668+
669+
Nor like this (which would happen without the negative margin):
670+
| ─────────┐
671+
| (R) │ std │
672+
| └─────┘
673+
*/
674+
margin-top: -16px;
675+
border-top: solid 16px transparent;
676+
box-sizing: content-box;
677+
position: relative;
678+
background-color: var(--sidebar-background-color);
679+
background-clip: border-box;
680+
z-index: 1;
681+
}
682+
644683
.sidebar-crate h2 a {
645684
display: block;
646685
/* extend click target to far edge of screen (mile wide bar) */
647686
border-left: solid var(--sidebar-elems-left-padding) transparent;
648-
background-clip: padding-box;
687+
background-clip: border-box;
649688
margin: 0 calc(-24px + 0.25rem) 0 calc(-0.2rem - var(--sidebar-elems-left-padding));
650689
/* Align the sidebar crate link with the search bar, which have different
651690
font sizes.

tests/rustdoc-gui/huge-logo.goml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go-to: "file://" + |DOC_PATH| + "/huge_logo/index.html"
55
set-window-size: (1280, 1024)
66
// offsetWidth = width of sidebar + left and right margins
77
assert-property: (".sidebar-crate .logo-container", {"offsetWidth": "96", "offsetHeight": 48})
8-
// offsetWidth = width of sidebar
9-
assert-property: (".sidebar-crate .logo-container img", {"offsetWidth": "48", "offsetHeight": 48})
8+
// offsetWidth = width of sidebar, offsetHeight = height + top padding
9+
assert-property: (".sidebar-crate .logo-container img", {"offsetWidth": "48", "offsetHeight": 64})
1010

1111
set-window-size: (400, 600)
1212
// offset = size + margin

0 commit comments

Comments
 (0)