Implementing a sticky sidebar that overlaps content on mobile with Bootstrap 4

I've been working on designing a website with Bootstrap 4, and I wanted to incorporate a sticky sidebar on the right side. My idea was to have two boxes - one for content and the other for the sidebar.

Everything is displaying correctly on most devices, except for mobile. On mobile, I want the sidebar to be above the content, but I'm running into issues with overlapping.

The problem lies in the fact that box 2 is overlapping box 1. I'm struggling to find a solution to this issue.

Here's the code snippet I have so far:

<style>
    .content-section {
    min-height: 2000px;
  }

  .sidebar-item {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .make-me-sticky {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
  }
</style>

<div class="container mt-4">
    <div class="row">
        <div class="col-md-8">
            <div class="content-section card card-body">
                <div>1</div>
            </div>
        </div>
        <div class="col-md-4 order-first order-md-last">
            <div class="sidebar-item">
                <div class="make-me-sticky">
                    <div class="card card-body">2</div>
                </div>
            </div>
        </div>
    </div>
</div>

You can view a demo of the layout here:

Answer №1

   <style>
    .content-section {
    min-height: 2000px;
  }

  .sidebar-item {
    position: relative; /* Updated from absolute to relative */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .make-me-sticky {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
  }
</style>

<div class="container mt-4">
    <div class="row">
        <div class="col-md-8">
            <div class="content-section card card-body">
                <div>1</div>
            </div>
        </div>
        <div class="col-md-4 order-first order-md-last">
            <div class="sidebar-item">
                <div class="make-me-sticky">
                    <div class="card card-body">2</div>
                </div>
            </div>
        </div>
    </div>
</div>

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

Is there a way to prevent the text in my text boxes from staying there when I refresh the page?

Currently working on an HTML5 project with Javascript, here is a snippet of my code: Your inquiry <textarea type="text" name="phrase" id="phrase" cols="50" rows="5" placeholder="Write your text here. . ."></textarea> I am looking for a way ...

Stop specific words from being entered on a website

Is there a way to block a specific word from being saved in my database? For example, if I want to prevent the term 'fast car' from being stored, what kind of code should I implement using HTML, JavaScript, or PHP on my website? ...

What is the most efficient method to use JavaScript to conceal unnecessary options?

I'm working with an HTML select element that has multiple options, and I need to be able to hide and show specific options as needed. Here's an example of my HTML code: <select> <option value="0">A</option> <option value="1" ...

Utilize Bootstrap to combine two tables within a single column efficiently

I am facing an issue with my layout that involves organizing 3 tables in a specific way. Two smaller tables are supposed to take up 3 bootstrap columns on the left side, while one larger table should occupy 9 columns on the right side. However, when I impl ...

Access several different dynamic URLs through a single Ajax request

I have a scenario where I am showing multiple dynamic links within the same div. The first link works perfectly fine with ajax loading the content, but the subsequent links do not work. How can I make it so that the content of all links can be loaded withi ...

Position is at the highest & leftmost point, with a rotation created by the

I need help with JavaScript code that can arrange playing card images in a specific layout, as shown in the attached image. I've been trying to use CSS transform rotate with a 7-degree angle, but I'm having trouble calculating the correct left an ...

Issue with transparent background appearing unexpectedly during fade in/out effect in Internet Explorer 8 while using jQuery galleria

For my girlfriend's birthday, I am working on a surprise website for her. However, I have encountered a minor visual problem in Internet Explorer 8 (and possibly 7) with the fade in/out effect when switching images in an iframe gallery. While other br ...

Retrieving HTML tag content using Javascript

I'm searching for a JavaScript code that can scan all the HTML files in my main directory and subfolders to extract content located within a specific tag, like this: <div id="content"> !!this content!! </div> Additionally, it should only ...

Obtain CSS3 gradient background-color of an element using JavaScript

Currently, I am using the following JavaScript (jQuery) to retrieve the background color (in RGB) of various other div elements: $theColor = $(this).css("background-color"); This method works perfectly, except when dealing with CSS3 gradients. For insta ...

Concealing Images in HTML Without Reserving Space for Them

Our task is to create a website here: I tried hiding elements using display: none; However, I ended up with a large blank space. https://i.sstatic.net/B2E8Y.jpg This is the HTML code: <h1>OUR PORTFOLIO</h1><div class="subtext-top"& ...

What is the process of transferring data from an HTML form to Firebase Realtime Database in Django using Pyrebase?

Currently, I'm facing an issue with transferring data from a form to the Firebase realtime database. Here's my view function. I made some changes by adding a user token, but unfortunately, it hasn't resolved the problem yet. The information ...

Is there a way to make the width of stacked multiple divs dynamically adjust to accommodate the longest content within them?

I am trying to adjust the width of stacked multiple divs dynamically based on the longest content, like shown in this image: https://i.sstatic.net/QhGCe.png After doing some research, I found that using inline-block is recommended. Here is my initial atte ...

Utilizing JQuery to create a dynamic background image slider that cycles through images extracted from a selection of

Case Study: Implementing a background-image slider with JQuery listening for window resizing. Depending on the screen size, a specific array is set as the image file paths source. Encountering a 6-second delay issue where the initial image does not displ ...

"Enhance your Design with Customized Text Box Coloring

I've made a change to the header's color, which consists of a logo and a title. Unfortunately, the text box where the title appears is picking up the background color of the body of the website instead of the background color of the header. ...

Troubleshooting code: JavaScript not functioning properly with CSS

I am attempting to create a vertical header using JavaScript, CSS, and HTML. However, I am facing an issue with the header height not dynamically adjusting. I believe there might be an error in how I am calling JSS. Code : <style> table, tr, td, t ...

onsubmit function was never triggered

Seems like a silly mistake, but I'm encountering an issue with my HTML form. Here's a snippet of the code: <form onsubmit="updateProfile();"> <input type="submit" value="Update Account"> .. ... </form> However, w ...

Encountering a parsing issue within my React program

I keep encountering a parsing error while trying to run my React application The compilation fails with the following error message: ./src/App.js Line 7: Parsing error: Unexpected token, expected "{" After reviewing my code, I couldn't find any unex ...

Is it possible to embed a Blazor component as a Web Component in a standard HTML page that is not using Blazor?

Is there a way to render a Blazor component as a standalone DOM fragment, or integrate it as a standard Web Component in a vanilla HTML/JS page? This question may seem simplistic from the perspective of Blazor architecture. While I'm no expert in Bla ...

Exploring JSON without taking into account letter case

Looking to conduct a case-insensitive search in a JSON file? Here's the JSON data you can work with: { "Data" : [ {"Name": "Widget", "Price": "25.00", "Quantity": "5" }, {"Name": "Thing", "Price": "15.00", "Quantity": "5" }, {"Nam ...

Choosing a dynamic dropdown option using jQuery and AJAX

I am facing an issue with a select box that is dynamically populated and should display information about a single option. The problem I am encountering is that the browser does not trigger a ':selected' event when I click on any of the options. ...