Comments (10)
Another solution that worked for me is to set a same size top padding for the heading as your header height andc also a negative top margin for the heading. E.g.:
h1 {
padding-top: 60px; /* Size of your fixed header */
margin-top: -60px; /* If you need more spacing between the heading and the preceding element then fine tune this value */
}
from tocbot.
Thanks for using tocbot. I just updated the readme to explain how to handle fixed headers better. https://github.com/tscanlin/tocbot#fixed-headers
Basically, use CSS similar to the following:
h1::before, h2::before, h3::before, h4::before, h5::before, h6::before {
display: block;
content: " ";
height: 60px;
margin-top: -60px;
visibility: hidden;
}
Let me know how that works for you.
from tocbot.
Thanks! This works great except in the case where your header just has a background color. Then you get to see that extra height covering some of your pre-header content with that background color. Oddly, you can fix it by also giving the header a border. This may just be a quirk of bootstrap.
Here's a contrived example that demonstrates what I'm seeing in my site:
<div class="blue-box">
<pre>Content before header</pre>
<h2 style="max-width: 200px; background-color: rgba(255, 73, 73, 0.5);">Header!</h2>
<pre>Content after header</pre>
</div>
from tocbot.
Oh, you can also try adding overflow: hidden
to the header tag to hide the pseudo element from doing that. Hopefully it helps.
from tocbot.
I'm gonna close this but feel free to comment if you run into any other issues.
from tocbot.
Thanks for the help!
On a somewhat unrelated note, you might also want to document how to disable the smooth scrolling for specific links. I was getting unwanted automatic scrolling behavior from ZenScroll when using Bootstrap Collapse to expand/collapse elements.
from tocbot.
Thanks for the tip, that is good to note. I've updated the readme
from tocbot.
Good to know @peterzimon thank you for sharing!
from tocbot.
Thanks for using tocbot. I just updated the readme to explain how to handle fixed headers better. tscanlin/tocbot#fixed-headers
Basically, use CSS similar to the following:
h1::before, h2::before, h3::before, h4::before, h5::before, h6::before { display: block; content: " "; height: 60px; margin-top: -60px; visibility: hidden; }Let me know how that works for you.
Do you have to set headingSelector: 'h2::before, h3::before, h4::before'
for this to work? I tried that and it says Element not found: .post-content
where .post-content
is my contentSelector
.
If I remove the ::before
tags then nothing happens and it still scrolls to the top.
Thanks for your help!
from tocbot.
Let's make a new issue so we don't spam people who started this thread over a year ago ;)
from tocbot.
Related Issues (20)
- Flash when scrolling / doesn't scroll to right spot HOT 3
- tocbot links not getting highlighted HOT 1
- Scrolling tocbot and scrolling page HOT 8
- BUG: Links don't highlight on short pages HOT 1
- On complete callback HOT 1
- List generation with non-sequential heading levels HOT 7
- tocbot not working properly with id having emojis HOT 4
- How to use for WordPress? HOT 1
- TOC in `.xhtml` has no hierarchal structure (bookmark is flatten). HOT 1
- Is it possible to pass a function to format the links? HOT 1
- How can I let the Headings of tocbot indent to its corresponding position? HOT 4
- A problem occurred while using typescript HOT 9
- Navigation don't scroll to position with cyrillic characters ids HOT 6
- Regarding the description of the options, it is recommended to update HOT 15
- Help with large HTML, strange TocBot behaviour HOT 11
- Unusual issue with .is-active-link when there are multiple tocbots on a page HOT 1
- Overscroll support HOT 3
- the icon should stay original position when toc unfold HOT 6
- is-active-li not set on scroll or click, only on page load HOT 5
- can't work on hexo-theme-landscape HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tocbot.