Re: Alternative to Sticky Positioning

On Wed, Nov 7, 2012 at 7:19 AM, Rudolph Gottesheim <r.gottesheim@loot.at> wrote:
> I've got an alternative idea for the problem that Sticky Positioning[1] is
> trying to solve. I think it can potentially solve more use cases than just
> this one.
>
> What if we had a pseudo-class that matched elements based on whether they
> are inside the viewport or not? Then you could give the element a position:
> fixed when it is not. Like this:
>
> [role=navigation]:viewport-partially-hidden {
>     position: fixed;
>     top: 0;
>     left: 0;
> }
>
> Obviously, I'm bad in naming pseudo-classes, but you get the gist.
>
> It could also take an argument, like which part of the element is hidden (to
> stick something to the top/bottom of the viewport).
>
> What do you think?

Unfortunately, this suffers from basic circularity problems - your
pseudoclass applies when an element is outside of the viewport, but
then applies rules that put it back in the airport, so the pseudoclass
no longer applies, so it goes out of the viewport, so the pseudoclass
applies...

It also doesn't address the use-case quite right.  This pseudoclass
would apply when the page first loaded, if the element was below the
fold, and after the element's container scrolled off the top of the
screen, if it was sticky to its container rather than the viewport.

Finally, because your idea switches it to fixpos, which takes it out
of the normal flow, the content surrounding it would jump around when
it switched.  Stickypos is basically "magical relpos", where it still
takes up space in the flow.

~TJ

Received on Wednesday, 7 November 2012 17:35:06 UTC