GithubHelp home page GithubHelp logo

Make headers sticky? about whatwg.org HOT 4 OPEN

domenic avatar domenic commented on September 22, 2024
Make headers sticky?

from whatwg.org.

Comments (4)

domenic avatar domenic commented on September 22, 2024

Here was my initial attempt:

h2 { position: sticky; top: 0; background: white; }
h3 { position: sticky; top: 28px; background: white; }
h4 { position: sticky; top: 56px; background: white; }
h5 { position: sticky; top: 84px; background: white; }
h6 { position: sticky; top: 112px; background: white; }

The problem is that since we don't have sectioning containers, everything sticks to the top forever. If you add backgrounds (as I did above) this can be OK as, for each N, only the topmost hN shows. However this breaks down when you're looking inside a h4 and have recently scrolled past a h5; that recent h5 still shows up, leading to scenarios like this:

image

(Also, this really highlights how our section permalink markers are not lined up, boo.)

from whatwg.org.

domenic avatar domenic commented on September 22, 2024

There's also some z-index issues (easy to fix).

However the big problem here is that this breaks cross-links in the spec. They get hidden under the headers. Maybe there are margin or padding hacks you can do to fix that, but it's pretty bad. See https://stackoverflow.com/q/10732690/3191 and links from there for more.

from whatwg.org.

hober avatar hober commented on September 22, 2024

Some initial exploration makes me think that position: sticky was mostly designed to be used in conjunction with container elements

Yup, that's what I had in mind at the time.

from whatwg.org.

emilio avatar emilio commented on September 22, 2024

There's scroll-padding / scroll-margin you could use, to make sure you scroll at least to a "safe" place. (40% of the viewport height or such maybe? If that intersects with sticky headers somehow, then the sticky headers are probably being non-helpful at that point)

from whatwg.org.

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.