How do i modify where Table of Contents anchors to?

Halvard Meijer September 4, 2019

When Im clicking the links in table of contents it moves the page so the header it referred to is placed at the top of the screen. For me it needs to be placed X px down from the top. How can i achieve this?

Ive made a tiny illustration to show what it does now and what i want it to do. 

Hjelp.png

2 answers

1 accepted

1 vote
Answer accepted
Halvard Meijer September 6, 2019

I managed to fix this by adding some css to h2 tags in these pages. Because we are using the same naming convention it makes it easy to just style the h2 tags in the right pages. 

h1[id*="2019."]{

padding-top: 70px !important; 

margin-top-30px !Important;

}

0 votes
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 5, 2019

Hello, @Halvard Meijer !
As I understand, you need to customize where the automatic page scrolling of our Table of Contents macro stops after you click the link.
Is that correct?
If the above is correct, I can tell you that this is not currently possible. The Table of Contents macro relies on IDs from the webpage itself to work. Browsers have a native function to automatically scroll pages depending on the link that directs you there.

The link https://yourinstance.net will lead you to the start of your page. The link https://yourinstance.net#nextelement will land you right at the element with id nextelement.

As you can see in this screenshot:

Screen Shot 2019-09-05 at 18.36.18.png

What the ToC macro does is create a link that has the #<elementID> at the end. Even though the macro makes use of the <elementID>, the function itself is part of the browser, not Confluence.

Let us hear from you Halvard! Looking forward to your reply.

Halvard Meijer September 6, 2019

Thank you for the reply. The reason for this problem is because i made the header bigger and it made the heading hidden beneth the header. 

 

I managed to fix this by adding some css to h2 tags in these pages. Because we are using the same naming convention it makes it easy to just style the h2 tags in the right pages. 

h1[id*="2019."]{

padding-top: 70px !important; 

margin-top-30px !Important;

}

 

((I added this as a response and accepted it as an answer)) 

Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 6, 2019

Hello, Halvard!
Thank you very much for sharing the solution to this. Having some CSS styling can get us a long way!
This shared knowledge will probably help more users of our community.

Let us hear from you.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events