Skip to content

Commit 7b5e96f

Browse files
Make headings anchor hidden by default and show on hover
1 parent 62cd1bb commit 7b5e96f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

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

775791
.main-heading a:hover,
776792
.example-wrap .rust a:hover,
777793
.all-items a:hover,
778-
.docblock a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
794+
.docblock a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover:not(.doc-anchor),
779795
.docblock-short a:not(.test-arrow):not(.scrape-help):not(.tooltip):hover,
780796
.item-info a {
781797
text-decoration: underline;

0 commit comments

Comments
 (0)