Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb7e157

Browse files
sophiebitsvjeux
authored andcommitted
Make doc headers clickable again
...without preventing clicks on other things. Just use an `<a name="...">` tag that doesn't take up any space to make sure that we're not covering up something else. For whatever reason, doing `position: relative; top: -$navHeight;` doesn't work and causes the anchor target not to be moved up. This solution works in both Chrome and Firefox.
1 parent 8ead6dc commit fb7e157

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

docs/_css/react.scss

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,19 @@ li {
7777
// Make header navigation linkable and on the screen. Used in documentation and
7878
// blog posts.
7979
h1, h2, h3, h4, h5, h6 {
80-
&.anchor {
81-
position: relative;
82-
top: -$navHeight;
83-
z-index: -1;
84-
> a {
85-
color: $darkTextColor;
86-
position: relative;
87-
top: $navHeight;
80+
.anchor {
81+
margin-top: -$navHeight;
82+
position: absolute;
83+
}
8884

89-
&:hover {
90-
text-decoration: underline;
91-
}
92-
}
85+
&:hover .hash-link {
86+
display: inline;
9387
}
9488
}
89+
.hash-link {
90+
color: $mediumTextColor;
91+
display: none;
92+
}
9593

9694
// Main Nav
9795

docs/_plugins/header_links.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def header(title, level)
1111
.gsub(/\s+/, "-")
1212
.gsub(/[^A-Za-z0-9\-_.]/, "")
1313

14-
return "<h#{level} id=\"#{clean_title}\" class=\"anchor\"><a href=\"##{clean_title}\">#{title}</a></h#{level}>"
14+
return "<h#{level}><a class=\"anchor\" name=\"#{clean_title}\"></a>#{title} <a class=\"hash-link\" href=\"##{clean_title}\">#</a></h#{level}>"
1515
end
1616
end
1717

0 commit comments

Comments
 (0)