Giter Club home page Giter Club logo

Comments (10)

peterzimon avatar peterzimon commented on May 25, 2024 1

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.

tscanlin avatar tscanlin commented on May 25, 2024

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.

dankoster avatar dankoster commented on May 25, 2024

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>

image

from tocbot.

tscanlin avatar tscanlin commented on May 25, 2024

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.

tscanlin avatar tscanlin commented on May 25, 2024

I'm gonna close this but feel free to comment if you run into any other issues.

from tocbot.

dankoster avatar dankoster commented on May 25, 2024

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.

tscanlin avatar tscanlin commented on May 25, 2024

Thanks for the tip, that is good to note. I've updated the readme

from tocbot.

tscanlin avatar tscanlin commented on May 25, 2024

Good to know @peterzimon thank you for sharing!

from tocbot.

y1zhou avatar y1zhou commented on May 25, 2024

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.

tscanlin avatar tscanlin commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.