Skip to content

Commit a4e5e07

Browse files
Make headings anchor hidden by default and show on hover
1 parent 13b2156 commit a4e5e07

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,14 +765,30 @@ nav.sub {
765765
h2.section-header > .anchor {
766766
padding-right: 6px;
767767
}
768-
.doc-anchor {
769-
margin-right: 6px;
768+
a.doc-anchor {
769+
color: var(--main-color);
770+
display: none;
771+
position: absolute;
772+
left: -17px;
773+
/* We add this padding so that when the cursor moves from the heading's text to the anchor,
774+
the anchor doesn't disappear. */
775+
padding-right: 5px;
776+
/* And this padding is used to make the anchor larger and easier to click on. */
777+
padding-left: 3px;
778+
}
779+
*:hover > .doc-anchor {
780+
display: block;
781+
}
782+
/* If the first element of the top doc block is a heading, we don't want to ever display its anchor
783+
because of the `[-]` element which would overlap with it. */
784+
.top-doc > .docblock > *:first-child > .doc-anchor {
785+
display: none !important;
770786
}
771787

772788
.main-heading a:hover,
773789
.example-wrap .rust a:hover,
774790
.all-items a:hover,
775-
.docblock a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
791+
.docblock a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover:not(.doc-anchor),
776792
.docblock-short a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
777793
.item-info a {
778794
text-decoration: underline;

0 commit comments

Comments
 (0)