Jump to content

Responsive sidebar : make it sticky ! (help!?)


Seth666

Recommended Posts

Hello,

I'm pretty new to CSS (still basic in HTML too, learned it 20 years ago and didn't use it much) and I'm trying to figure out if I can make my responsive sidebar sticky at top position when scrolled down (while the responsive action moves the sidebar to the top).

Best example would be : https://www.w3schools.com/howto/howto_css_sidebar_responsive.asp

I used this how to. It's exactly the same CSS, no modification except for colors. If you resize the screen, the sidebar moves to the top which is what I want. But it doesn't "stick" there (on mobile and PC). I tried multiple ways of adding a sticky class with Javascript (window.onscroll which works really well for a Header div or top navbar div) or without Javascript. It seems that I can't do it. I must really be missing something.

As an additional thing, I would like to have a sticky header (top container) added to that. So I get a full frame (yeah I used to work with frames back in the time) at the top containing a logo on the left and some text on the right (would probably be ugly on mobile though, unless I can make it responsive to reduce the logo size and text format / hide text). The top container should not be over/under the sidebar when the sidebar moves to the top. The sidebar should be below the top container and be sticky. The top container on smaller screen does not have to be sticky. That would be amazing but it's not a top priority for now.

Thanks to anyone that can help!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...