简体   繁体   中英

Fixed div but stop before footer

i need fixed div (sidebar) but must stop before footer. I wrote a code, I've been on it for a week now and I can not do it -> pastebin.com/q85pPBpc

There is a very short CSS solution. It comes from Bootstrap 4. I suppose this is what you need.

Your website should have the following structure:

<header></header>
<main>
    <aside class="sticky-top"></aside>

    <section></section>
    <section></section>
    <section></section>
</main>
<footer></footer>

And simple CSS will make your sidebar aside sticky and it will remain in main section and will not go to footer.

@supports ((position: -webkit-sticky) or (position: sticky)) {
   .sticky-top {
       position: -webkit-sticky;
       position: sticky;
       top: 0;
       z-index: 1020;
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM