Bootstrap`s sidebar with fixed footer and scrollable div

10,228

You can use the following HTML code:

<div class="container-fluid">
  <div class="row">
    <div class="col-xs-3">
      <div style="position:fixed; top:0; bottom:40px; overflow-y:scroll; float:none; width:inherit;">
      <footer style="position:fixed; bottom: 0; height:40px; background-color:red;">footer</footer>        
      </div>
    </div>
    <div class="col-xs-9">
    </div>        
  </div>    
</div>  

The left side and its footer both get a position: fixed Notice the width: inherit which guarantees that the fixed column gets the same width as its parent. You can do the same for the footer.

To active the scroll bar you should set both the top and bottom properties according to Have a fixed position div that needs to scroll if content overflows

Share:
10,228
Nurzhan Nogerbek
Author by

Nurzhan Nogerbek

✌️ Hello, friend! I am glad to see you on my personal StackOverflow profile. My name is 𝗡𝘂𝗿𝘇𝗵𝗮𝗻. 🏠 I am living in 𝗔𝗹𝗺𝗮𝘁𝘆 🍎 and I am from 𝗞𝗮𝘇𝗮𝗸𝗵𝘀𝘁𝗮𝗻 🇰🇿. 👦🏻 Since I first wrote my first piece of code in 𝗧𝘂𝗿𝗯𝗼 𝗣𝗮𝘀𝗰𝗮𝗹 as a child using my father's personal computer in 𝗪𝗶𝗻𝗱𝗼𝘄𝘀 𝟵𝟱, software development has become my passion. ⏱ I still live with this passion in the commercial software development industry, where I have been working for 𝟱+ years. 🏢 I started my career from developing multi-user web applications for the outsourcing company 𝗥𝘂𝗯𝗶𝘂𝘀 in 2015. 🏦 Then I worked for 1.5 years in the 𝗞𝗮𝘇𝗮𝗸𝘀𝘁𝗮𝗻 𝗦𝘁𝗼𝗰𝗸 𝗘𝘅𝗰𝗵𝗮𝗻𝗴𝗲 in FinTech projects. During this short time, I managed to develop 𝟰 financial and analytical web projects for the company. 📡 I worked for the largest telecommunications company in Central Asia from 2018 to 2020. I am proud to have participated in the creation of 𝟳 scalable distributed Big Data systems in a microservice architecture at 𝗩𝗘𝗢𝗡 company. 🚀 Since the fall of 2020, I have been involved in the development of a fast-growing and promising startup at 𝗦𝗺𝗮𝗿𝘁𝗟𝗮𝗯 company. 🛠 I usually use 𝗚𝗼𝗹𝗮𝗻𝗴 for 𝗕𝗮𝗰𝗸𝗲𝗻𝗱 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗺𝗲𝗻𝘁, 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 for 𝗙𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗺𝗲𝗻𝘁, 𝗦𝗰𝗮𝗹𝗮 for 𝗗𝗮𝘁𝗮 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿𝗶𝗻𝗴, and 𝗣𝘆𝘁𝗵𝗼𝗻 for 𝗗𝗮𝘁𝗮 𝗦𝗰𝗶𝗲𝗻𝗰𝗲. 📚 I have a 𝗠𝗮𝘀𝘁𝗲𝗿'𝘀 𝗗𝗲𝗴𝗿𝗲𝗲 in 𝗖𝗼𝗺𝗽𝘂𝘁𝗲𝗿 𝗦𝗰𝗶𝗲𝗻𝗰𝗲 from 𝗧𝗼𝗺𝘀𝗸 𝗣𝗼𝗹𝘆𝘁𝗲𝗰𝗵𝗻𝗶𝗰 𝗨𝗻𝗶𝘃𝗲𝗿𝘀𝗶𝘁𝘆 in Russia. 🤖 I have implemented 𝟭𝟱+ successful web projects that have made life easier for thousands of users. You can easily find details of these projects in my GitHub profile. 📩 Feel free to contact me with your ideas and suggestions!

Updated on June 28, 2022

Comments

  • Nurzhan Nogerbek
    Nurzhan Nogerbek almost 2 years

    As you see from the picture below the part of sidebar where I have scrollable TreeView didnt work, also I need to have fixed footer to this sidebar that doesn't move when user scroll the sidebar. How to fix it? enter image description here

    I want to have next structure. enter image description here

    .html

    <div class="container-fluid max-height no-overflow">
            <div class ="row max-height">
                <form runat="server">
                        <!--SIDEBAR-->
                        <div class="col-sm-3 sidebar">
    
                            <div class="panel-body  scrollable">
                                TREEVIEW HERE
                            </div>
    
                            <div class="panel-footer center-block">
                                BUTTON HERE
                            </div>
                        </div>  
    
                    <!--MAIN CONTENT-->
                    <div class="col-sm-offset-3 main scrollable">
                        MAIN CONTENT HERE
                    </div>
                </form>
             </div>
         </div>
    </div>
    

    css:

            .scrollable {
                height: 100%;
                overflow: auto;
            }
            .max-height {
                height: 100%;
    
            }
            .no-overflow {
                overflow: hidden;
            }
            .sidebar {
                display: none;
            }
            @media (min-width: 768px) {
                .sidebar {
                    position: fixed;
                    bottom: 0;
                    left: 0;
                    z-index: 1000;
                    display: block;
                    overflow-x: auto;
                    overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
                    background-color: #f5f5f5;
                }
            }
            .main {
                padding-top: 20px;
    
            }
            @media (min-width: 768px) {
                .main {
                    padding-right: 20px;
                    padding-left: 20px;
    
                }
            }
            .panel-body{
                overflow: auto;
            }
            .panel-footer{
                background-color:#ff6a00;
            }