hugo-PaperMod icon indicating copy to clipboard operation
hugo-PaperMod copied to clipboard

Ability to stick header to the top of the page

Open Wirone opened this issue 3 years ago • 5 comments

What does this PR change? What problem does it solve?

If enabled (using stickyHeader param), header with top menu will be always visible regardless of scrolling.

Live Demo.

  • Works on desktop and mobile
  • Supports dark/light modes
  • 100% backward compatible

Was the change discussed in an issue or in the Discussions before?

No.

PR Checklist

  • [ ] This change adds/updates translations and I have used the template present here.
  • [x] I have enabled maintainer edits for this PR.
  • [x] I have verified that the code works as described/as intended.
  • [ ] This change adds a Social Icon which has a permissive license to use it.
  • [x] This change does not include any CDN resources/links.
  • [x] This change does not include any unrelated scripts such as bash and python scripts.
  • [ ] This change updates the overridden internal templates from HUGO's repository.

Wirone avatar Jul 12 '22 09:07 Wirone

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Jul 12 '22 09:07 sonarqubecloud[bot]

Thanks for the great feature~. But it will hide some content after clicking on the Table of Contents.

Here is my workaround: add this to the assets/css/common/header.css

html {
    scroll-padding-top: calc(var(--header-height) * 2);
}

I hope this help.

ngntrgduc avatar Jul 28 '23 04:07 ngntrgduc

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Nov 02 '23 08:11 sonarqubecloud[bot]

@ngntrgduc Thanks for the great tip! I encountered this issue on my blog, but ignored it as I did not want to spend my time on it, however I've just applied your snippet and it really helps 🙂. Just added it to this PR.

I am not up-to-date with modern CSS tricks, so let me know if there's a way of applying this to html conditionally when header has header-sticky class included. Maybe there's no need to apply header-sticky also to html 😉.

Wirone avatar Nov 02 '23 08:11 Wirone

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Dec 11 '23 12:12 sonarqubecloud[bot]