Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page scrolls past table of contents header anchor points #115

Open
rbraddev opened this issue Aug 6, 2021 · 13 comments
Open

Page scrolls past table of contents header anchor points #115

rbraddev opened this issue Aug 6, 2021 · 13 comments
Labels
help wanted Extra attention is needed

Comments

@rbraddev
Copy link

rbraddev commented Aug 6, 2021

When a link is clicked in the table of contents, the page scrolls to just past the start of the first paragraph rather than to the start of the header.

@styxlab
Copy link
Owner

styxlab commented Aug 6, 2021

Thanks for noting. Don't know why the root margin displacement defined in useActiveHash is not working. Will need to analyze further.

@styxlab styxlab added the help wanted Extra attention is needed label Aug 12, 2021
@styxlab
Copy link
Owner

styxlab commented Aug 12, 2021

The correct header displacement should be handled by the toc.css style file. I have no clue why it is not coming through correctly. I added the help wanted label to this issue, so maybe someone else is quicker in finding out the root cause.

@seoxyz
Copy link

seoxyz commented Sep 15, 2021

izinkan saya menjawab.. 🙏 @styxlab
toc.css "display block" doesn't work in flex area. the solution is to add comment tag or remove "html.casper .post-content" part in screen.css

Screenshot_20210915-205750

toc

@styxlab
Copy link
Owner

styxlab commented Sep 16, 2021

@seoxyz Thanks for finding out the root cause of this issue ❤️ I'll add you to the contributors list right away and will think about how to best fix it later this week.

Repository owner deleted a comment from allcontributors bot Sep 16, 2021
@styxlab
Copy link
Owner

styxlab commented Sep 16, 2021

@all-contributors please add @seoxyz for code

@allcontributors
Copy link
Contributor

@styxlab

I've put up a pull request to add @seoxyz! 🎉

@seoxyz
Copy link

seoxyz commented Sep 16, 2021

Thanks @styxlab 🙏

@styxlab
Copy link
Owner

styxlab commented Sep 19, 2021

The problem is not easily fixed, it turns out to be a side effect of #31. The situation is as follows: Reverting the change of #31 would solve this issue here, but the wide image alignment issue would re-appear. One more note. screen.css should be left untouched as styles can be overwritten in toc.css. Any ideas welcome.

@Garfounkel
Copy link

Garfounkel commented Dec 30, 2021

One way to do it might be to modify the htmlAst during the generation of the toc to add a simple div with the right id in front of each header elements:

<h2 id="my-header">My header</h2>

becomes:

<div id="my-header" style="position: relative; top: -80px;"></div>
<h2 id="my-header">My header</h2>

Works on my browser. However I'm not sure how to modify the htmlAst in place or even if it's a good idea. I'll happily give a try at a PR for this if someone can point me in the right direction. Edit: I found another solution using a script to modify the HTML page after it loaded, see #115 (comment) for the PR.

@Garfounkel
Copy link

On a side note, you can bypass the issue from the Ghost editor by adding the div code in a html embed.
Let's say your header is called "My Header", you can add the following in a html embed right before your header:

<div id="my-header" style="position: relative; top: -80px;"></div>

However, it requires modifying the content of all your posts/pages. Not ideal.

@Garfounkel
Copy link

Here's a PR #150 to fix this. It patches the html after the page loaded to add divs with the correct id right before each header.

@styxlab
Copy link
Owner

styxlab commented Jan 9, 2022

Thanks @Garfounkel! I will have a look at your suggestions and PRs later this week. (@all-contributors please add @Garfounkel for code).

@allcontributors
Copy link
Contributor

@styxlab

I've put up a pull request to add @Garfounkel! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants