What is the best way to add scrolling functionality only to the center panel in Bootstrap 4, while keeping the navbar and sidebar fixed in place?

I'm seeking guidance on how to implement the layout shown in the image using bootstrap 4: https://i.sstatic.net/mbEVu.png

I've come across numerous examples on stackoverflow with similar concepts, but I haven't been able to figure out how to make only the center panel scrollable. I am looking for something akin to this: https://www.codeply.com/go/woeJ9JxCQn. However, the issue with this layout is that the entire page is scrollable. My goal is to have the center panel always match the height of the window and have the content inside it be scrollable so that the scrollbar resembles the mockup. Can anyone offer a solution?

Answer №1

One possible solution is to make the navbar sticky instead of fixed. Then adjust the body padding and set appropriate heights and overflow for the sidebar and content area.

Link to example

<div class="container-fluid sticky-top bg-dark shadow">
    <div class="row collapse show no-gutters d-flex h-100 position-relative">
        <div class="col-3 px-0 w-sidebar navbar-collapse collapse d-none d-md-flex">
            <a href="#" class="navbar-brand">Brand</a>
        </div>
        <div class="col px-3 px-md-0 py-3">
            <div class="d-flex">
                <a data-toggle="collapse" href="#" data-target=".collapse" role="button" class="">
                    <i class="fa fa-bars fa-lg"></i>
                </a>
                <a href="#" class="ml-auto text-white"><i class="fa fa-cog"></i></a>
            </div>
        </div>
    </div>
</div>
<div class="container-fluid px-0">
    <div class="row vh-100 collapse show no-gutters d-flex h-100 position-relative align-items-start">
        <div class="col-3 p-0 min-vh-100 text-white w-sidebar navbar-collapse collapse d-none d-md-flex sidebar">
            <div class="navbar-dark bg-dark position-fixed h-100 w-sidebar">
                <h6 class="px-3 pt-3">Fixed Menu</h6>
                <ul class="nav flex-column flex-nowrap text-truncate">
                    <li class="nav-item">
                        <a class="nav-link active" href="#">Active</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Link</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Link</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Link</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Link</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Link</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="col p-3 overflow-auto h-100">
            <h3>Content..</h3>
        </div>
    </div>
</div>

Answer №2

To create a fixed navigation layout, set the side-nav and top-nav to have a fixed position. Add a margin-top to the content panel equal to the height of the top-nav, and a margin-left equal to the width of the side-nav. This will result in only the content being scrollable. Remember to set the side-bar's height to 100% or 100vh to prevent stretching.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

List without order - item position in the list

I currently have a website featuring 5 pages, with the main navigation displayed using an unordered list. My goal is to have the "active" page displayed first in the list. For example, if my pages are "Home | About | Contact | Blog" and the user is on the ...

PHP sanitize or format HTML content

I'm struggling to articulate my question properly, so I'm reaching out for your assistance. I have a block of HTML code that was created in a <textarea> tag using a WYSIWYG editor. Prior to saving and submitting the form, I want to standa ...

Guide on incorporating content from external pages into a modal using the latest version of Bootstrap, 4.4.x

I am looking to incorporate content from an external page into a Bootstrap 4.4 modal. You can view my demo here. JS: $('#theModal').on('show.bs.modal', function (e) { var button = $(e.relatedTarget); var modal ...

Tips for preventing a photo's placement from shifting while you are scrolling

I am struggling to keep my background photo positioned the same way as the viewer scrolls down on my landing page. I want it to remain fixed relative to the screen, just like in this example website where the girl's face stays in place as you scroll d ...

Tips for toggling password visibility by clicking outside a password field

As I work on creating a password field that allows users to toggle the visibility of their password by clicking an eye icon, I am facing a challenge. I want the password to be hidden automatically when the user clicks outside the field, which requires a co ...

Why isn't the Full Calendar loading automatically within a Bootstrap Tab?

I have been working on a travel website and incorporated a bootstrap tab feature. In the first tab, I have some content, while in the second tab, I've added a full calendar with JavaScript. Everything seems to be functioning correctly when the full ca ...

jQuery does not have the capability to access the href attribute through DOM manipulation

I've been trying to extract the href attribute from a link in my code and create a new link using that attribute. However, I'm facing an issue where the created link doesn't seem to work properly - it keeps showing a 404 error message like t ...

Breaking apart images with HTML5 canvas

I am currently working on creating a sliding puzzle piece game. By utilizing the canvas element, I successfully divided the image into multiple pieces. To shuffle these pieces, I stored their coordinates in an array, randomized the coordinates, and then up ...

Shift the Search bar to the last position on the navigation bar

I'm looking to relocate the search icon and input field to the end of the navbar. I'm currently using Bootstrap 5.0.2, but I am still new to Bootstrap, HTML, and CSS, so I'm not sure how to accomplish this. I want the width of the search box ...

How can we begin to create this dynamic animation?

Can someone help me figure out how to create an animation effect similar to the one seen in this link? I have some basic knowledge of css and html5, but I'm not sure where to start. Is this done with css, html5, plugins, or something else? I am looki ...

I'm looking for a tool that can convert Flash/Flex AS3 TextLayoutFormat data into HTML and CSS

I have been tasked with converting a flex app into HTML and CSS. The existing app relies heavily on TextFlow for content layout, requiring precise positioning within a few pixels. The current data structure looks like this: <p paragraphstartindent="0" ...

EaselJS - Utilizing multiple canvases with varying frame rates

Currently, I am exploring EaselJS by creating two animation instances using sprite sheets on two separate canvases positioned at different locations but with the same z-index. The issue I am facing is that these instances are not layered properly. My setup ...

How can Angular CLI prevent the submission of an HTML form unless a previous option has been selected

I am currently working on a form that contains select fields with various options pre-populated. <form [formGroup]="selectVehicleForm"> <select formControlName="Manufacturer"> <option *ngFor='let ...

Calculate the product of the input values

When appended, inputs become invisible to jQuery. There are a total of 3 inputs. <input class="bul-order-info__input bul-order-info__price" type="text" name="price" value="500" readonly> <input class="bul-order-info__input bul-order-info__qnt" ty ...

The input field does not accept any values even after setting it to be editable

Hey there! I have a specific requirement where I need to edit certain fields by clicking on an edit link. Initially, these fields will be disabled and in a readonly state. Once I click on the edit link, the field should become blank and editable. The issu ...

Designing a unique layout using the Bootstrap grid system

Can someone help me achieve a responsive bootstrap grid layout as shown below? If screen size is equal to or greater than 576px: https://i.sstatic.net/v44dE.png If screen size is less than 576px: https://i.sstatic.net/mnPPp.png Thank you for your assist ...

The innerHTML property of the iframe element returns null

Yesterday, the code was functioning properly as iframe[0].contentWindow.document.body.innerHTML displayed "success". However, today, both iframe[0].contentWindow.document.body and iframe[0].contentDocument.body are empty. The innerHTML cannot be found. ht ...

Using jQuery to replace the dynamic keyword in HTML content

<div class="fotorama__stage__frame magnify-wheel-loaded fotorama_vertical_ratio fotorama__loaded fotorama__loaded--img fotorama__active" aria-hidden="false" data-active="true" style="left: 0px;" href="https://static.domain.com/media/catalog/product/cach ...

What is the best way to ensure that a canvas created using JavaScript spans 100% of the width?

Working with a canvas element generated by Javascript, see the code snippet below: http://jsfiddle.net/mtvzgnmm/ <div id="circle"></div> <script> $('#circle').circleProgress({ value: 0.75, size: 400, ...

Is there a way to exclude the Unicode character from the first menu item while still utilizing it in the other items on my menu?

I have been working on customizing my menu by using the unicode character \25C6 to represent a black solid diamond as a spacer between labels. After searching for solutions on Stack Overflow, I attempted to implement the suggested method using the bef ...