简体   繁体   中英

How to keep sidebar layout fixed, not scrollable with bootstrap?

I am trying to make a simple admin panel. I added a sidebar as layout. I want to keep it fixed. But when I scroll down the page my sidebar also scrolls down. Here is how it looks at the beginning of page:

在此处输入图像描述

And when I scroll down the page:

在此处输入图像描述

I want to keep it as in picture 1 even the page is scrolled down. The beginning of siderbar is like this:

<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar" style="max-height:100%">

Edit: I tried .navbar-nav { position: fixed; left: 0; top: 0; bottom: 0, width: 150px; } .navbar-nav { position: fixed; left: 0; top: 0; bottom: 0, width: 150px; } .navbar-nav { position: fixed; left: 0; top: 0; bottom: 0, width: 150px; } and result is: 在此处输入图像描述

Try this way

<div class="container-fluid">
    <div class="row">
        <div class="col-md-3 px-1 bg-dark position-fixed">
            ...
        </div>
        <div class="col-md-offset-3 col-md-9 col-sm-12">
            <h1>Main Area</h1>
            ...
        </div>
    </div>
</div>

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