The sticky-top class in Bootstrap-4 seems to be malfunctioning

I am trying to create a layout with two columns, where the left column remains fixed while scrolling and only the right column scrolls. I don't want to use position: fixed because it affects the document flow.

Although I have looked into using the Bootstrap class sticky-top, unfortunately, it is not working for my specific case.

I have reviewed other answers and solutions, including this one, but none of the parent elements of the column I want to fix have the overflow property set.

Below is the code snippet I am working with:

<div class="row mb-4">
    <div class="col-3 sticky-top">

        <div class="row mb-4">
            <div class="col-12 mb-5">
                <div class="border border-secondary px-3 py-2">
                    <input type="number" class="form-control mb-3" placeholder="Enter Deal ID Here">
                    <button class="btn btn-primary rounded-0 w-100">Lookup Deal</button>
                </div>
            </div>
            <div class="col-12 mb-5">
                <div class="border border-secondary px-3 py-2">
                    <input type="text" class="form-control mb-3" placeholder="Enter EU Name Here">
                    <input type="text" class="form-control mb-3" placeholder="Enter Partner Name Here">
                    <button class="btn btn-primary rounded-0 w-100">Add Revenue</button>
                </div>
            </div>
        </div>
    </div>
    <div id="phsc_data" class="col-9 table-active">
        <!--BASE REBATES-->
        <div class="row">
            <table class="table table-light table-hover">
                <caption class="font-weight-bold pl-2">Base Rebates</caption>
                <thead class="">
                <tr>
                    <th scope="col">LOB</th>
                    <th scope="col">Product Name</th>
                    <th scope="col">Product Category</th>
                    <th scope="col">Revenue</th>
                    <th scope="col">Rebate</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>CSG</td>
                    <td>
                        <select class="form-control" name="" id="">
                            <option value="">ABC</option>
                            <option value="">DEF</option>
                        </select>
                    </td>
                    <td>Client A</td>
                    <td><input class="form-control" type="number" value="12345"></td>
                    <td>185</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

Answer №1

Wouldn't it be better to include a placeholder div to prevent the sticky behavior from affecting the normal div?

To achieve this, you can utilize position:fixed for the sticky behavior, as demonstrated in the following snippet of code:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<div class="container-fluid">
  <div class="row mb-4">
    <div class="col-12 col-sm-3 sticky-placeholder">
    </div>
    <div class="col-12 col-sm-3 sticky-top">
      <div class="row mb-4">
        <div class="col-12 mb-5">
          <div class="border border-secondary px-3 py-2">
            <input type="number" class="form-control mb-3" placeholder="Enter Deal ID Here">
            <button class="btn btn-primary rounded-0 w-100">Lookup Deal</button>
          </div>
        </div>
        <div class="col-12 mb-5">
          <div class="border border-secondary px-3 py-2">
            <input type="text" class="form-control mb-3" placeholder="Enter EU Name Here">
            <input type="text" class="form-control mb-3" placeholder="Enter Partner Name Here">
            <button class="btn btn-primary rounded-0 w-100">Add Revenue</button>
          </div>
        </div>
      </div>
    </div>
    <div id="phsc_data" class="col-12 col-sm-9 table-active">
      <!--BASE REBATES-->
      <p>
        Lorem Ipsum is simply dummy text of the printing and typesetting industry.
      </p>
      
      <!-- More Lorem Ipsum content -->

      <div class="row">
        <table class="table table-light table-hover">
          <caption class="font-weight-bold pl-2">Base Rebates</caption>
          <thead class="">
            <tr>
              <th scope="col">LOB</th>
              <th scope="col">Product Name</th>
              <th scope="col">Product Category</th>
              <th scope="col">Revenue</th>
              <th scope="col">Rebate</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>CSG</td>
              <td>
                <select class="form-control" name="" id="">
                  <option value="">ABC</option>
                  <option value="">DEF</option>
                </select>
              </td>
              <td>Client A</td>
              <td><input class="form-control" type="number" value="12345"></td>
              <td>185</td>
            </tr>
          </tbody>
        </table>
      </div>
      
    </div>
  </div>
</div>

<style>
  @media screen AND (min-width:576px) {
    .sticky-div {
      position: fixed;
      overflow-y: scroll
    }
    .sticky-placeholder {
      display: none
    }
  }
</style>

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

I am currently developing a system for managing portals and I am looking to implement individual pages for each employee using php

I'm currently developing a web portal, but I'm struggling with the process of generating dynamic pages for each user upon registration using PHP. Can anyone provide some guidance on this? ...

ngSwitchCase provider not found

While following a tutorial and trying to implement what I learned, I encountered an error that I'm having trouble understanding. The browser console shows an error message stating [ERROR ->]<span *ngSwitchCase="true">, but I can't figure ...

difficulties switching content between different screen sizes

Having trouble with hidden-xs and visible-xs-* classes not working as expected. Even a simple code snippet like the following doesn't hide the content: <div class="hidden-xs"> test test test </div> Even when scaling down my window to ...

Tips for enhancing modal popups

I would like to have a window similar to this one appear after an error message. https://i.sstatic.net/0mnRU.png Here is the outcome I am looking for: https://i.sstatic.net/cFWXU.png Could you please advise me on how to achieve the same result? <!-- ...

Troubleshooting Issue with Bootstrap 4 Modal Varying Content Display

Dealing with a minor issue where I'm unable to get a modal to fetch data from an HTML table and populate it into a Bootstrap 4 Modal. I've attempted various methods as evident in the code snippets below. Currently in a learning phase, I need to ...

Placing text inside a designated element on a different web page upon clicking a button

Imagine a scenario where a user is browsing a website and lands on the 'prices' page. They come across a product that catches their eye and decide to click on the associated button. This action redirects them to the 'contact us' page, w ...

Optimizing Container size for devices with smaller screens

After creating a container with a panel and a panel body, everything looked fine when viewed on desktop. However, upon checking it on my phone, I noticed a large space on the right with nothing there. If you'd like to see an image of the issue, click ...

The heights of the dropdown menu and button vary in size within the Dash Plotly Python framework

I'm currently working on creating a dashboard using dash in Python and I need help aligning 2 dropdowns and a button horizontally. This is the html.Div code snippet that I have been working on: html.Div([ html.Div( dcc.Dropdown( ...

AngularJs fails to render CSS styles

I'm encountering a small issue with my angularJS code. I am attempting to showcase JSON data that includes both CSS and HTML code. However, on my website, all that is displayed is a hard-coded form of HTML and CSS (resembling the code below). I have t ...

What is the best way to adjust the height of a div based on its child content

I've been experimenting with various methods to extend the white background around the title to cover the rest of the content. I've tried using overflow, clear, min-height, max-height, and even the '*' selector but nothing seems to work ...

Creating responsive columns in Bootstrap 4

Recently delving into Bootstrap to create a responsive banner, I spent time researching last night and this morning. If my question has already been answered elsewhere, please direct me to the source. I have set up a grid with 4 columns in one row, placing ...

The mobile site is extending beyond the width of the device screen

After creating this single web page and testing it on my mobile device, I noticed an issue. When I swipe to the left, the website's width shifts slightly, as if the edges are not fully contained within the screen. This problem only occurs on Safari, n ...

Having difficulty scrolling down in a section with 100% height on iOS devices

Currently facing an issue with a website I am creating for my wedding invitation. The top section is set to have a 100% height and requires scrolling to view the rest of the content. While it functions perfectly on FireFox / Chrome on my computer, there s ...

At what point does a dynamically loaded CSS file in the head section of a webpage actually

If the answer is already out there somewhere, I would really appreciate a link because I just can't seem to find it. When loading .php pages, I either include 'header.php' directly with <?php include 'header.php'; ?> or on ...

An artistic arrangement of images seamlessly fitting together in a rectangular shape using HTML and CSS

I am currently working on creating a collage of images that need to fit perfectly within a rectangle. I have successfully completed the top layer, but I am facing some confusion with arranging the images in the last row using CSS. (For better visualization ...

What could be causing my mobile page to require two scrolls?

I've encountered a peculiar issue where users need to scroll twice or the page gets stuck on mobile devices that are less than 600px wide. I've attempted the following solutions with no success. I am a complete novice, so please excuse my lack of ...

Extracting text from a grid view in jQuery to style with CSS

My asp.net datagrid's HTML is displayed below in the browser: <div id="divViewAlldealers" class=""> <table id="ctl00_cph1_ucMS_grdAllDealers" cellspacing="0" border="1" style="border-collapse:collapse;" rules="all"> <tbody> ...

Using flex and align properties to position two elements on the right and one on the left is a common layout challenge

I'm facing an issue with element positioning and text alignment. The navigation container consists of three elements: logo, title, and nav-list. You can find the code on CodePen. /**{ margin: 0; padding: 0; box-sizing: ...

The issue of the responsive navigation bar overlapping the header and navigation links not functioning properly

Hello everyone, I need some help with my website! I can't seem to find the answer on my own. I'm currently working on making my website responsive, but I've run into an issue with the mobile navigation on phones. The navigation links are ov ...

Slider Adjusts Properly on Chrome, but Not on Firefox

Visit this URL This link will take you to the QA version of a homepage I've been developing. While testing, I noticed that the slider on the page works perfectly in Chrome and IE, but has layout issues in Firefox where it gets cutoff and moved to th ...