Site logo

Archived topic

How can I make the two last widgets sticky in the sidebar?

3 replies · Started by Eve on April 13, 2021

Viewing posts 1–4 of 4

Hey guys,

is it possible you can post the CSS Code to make the last 2 widgets in the right sidebar sticky?

I have the last one sticky, but like to add another one.

Thanks

Hi there,

Can you link us to the page with the sidebar sticky you're working on so we could inspect for the CSS writeup?

You can provide the link on the private information text field. Let us know. :)

Hi there,

its possible by changing your sticky sidebar CSS to:

@media (min-width: 769px) {
    .site-content {
        display:flex
    }

    .inside-right-sidebar {
        height: calc(100% -  60px); /* Stop last widget from overlapping footer */
    }

    /* Sitck last 2 sidebar widgets */
    .inside-right-sidebar aside:last-child,
    .inside-right-sidebar aside:nth-last-child(2) {
        position: -webkit-sticky;
        position: sticky;
        top: 60px;
    }
    /* adjust top position of last widget */
    .inside-right-sidebar aside:last-child {
        top: 600px; /* Adjust accordingly */
    }
}

I added some comments to explain .... HOWEVER - its not perfect. To start it relies on setting the last widget Top position to be greater than the height of the previous widget. That height may change on smaller width screens. Also you cannot stop the last widget from overlapping the previous widget when scrolled to bottom.

To counter those side effects would need Javascript :(

This archived topic is closed to new replies.