Creating a persistent div with fixed positioning, vertical overflow, and spanning the entire width using Bootstrap 4

I'm looking for a way to create two columns with two tables using Bootstrap 4.1. I want the right table to be fixed with auto overflow, but when I try to do this, the table does not span the full width of the column. Are there any bootstrap solutions or other methods to achieve this?

This is how it should work: when a user selects a row in the left table, additional data should be loaded and displayed in the right table.

#table_div {
  position: fixed;
  height: 100vh;
  overflow: auto;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<div class="container">
  <div class="row my-3">
    <div class="col-6">
      <table class="table table-sm table-hover">
        <thead>
          <tr>
            <th scope="col">r1</th>
            <th scope="col">r2</th>
            <th scope="col">r3</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>1</td>
            <td>2</td>
            <td>3</td>
          </tr>
          (more table data here)
        </tbody>
      </table>
    </div>
    <div class="col-6">
      <div>
        <div id="table_div">
          <table class="table table-sm table-hover" id="my_table">
            <thead>
              <tr>
                <th scope="col">r1</th>
                <th scope="col">r2</th>
                <th scope="col">r3</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>1</td>
                <td>2</td>
                <td>3</td>
              </tr>
              (more table data here)
            </tbody>
          </table>
        </div>
        <div></div>
      </div>
    </div>
  </div>
</div>

REAL DATA - https://jsfiddle.net/hdb1783y/4/

Answer №1

Updated the required div by adding the abc class and applying the following style:

.abc {
  max-height: 100vh;
  overflow: auto;
  position: fixed;
  width: 50%!important;
}

.abc {
  max-height: 100vh;
  overflow: auto;
  position: fixed;
  width: 50%!important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<div class="container">
  <div class="row my-3">
    <div class="col-6">
      <table class="table table-sm table-hover">
        <thead>
          <tr>
            <th scope="col">r1</th>
            <th scope="col">r2</th>
            <th scope="col">r3</th>
          </tr>
        </thead>
        <tbody>
          [Table rows omitted for brevity]
        </tbody>
      </table>
    </div>
    <div class="col-6">
      <div>
        <div id="table_div" class="abc">
          <table class="table table-sm table-hover" id="my_table">
            <thead>
              <tr>
                <th scope="col">r1</th>
                <th scope="col">r2</th>
                <th scope="col">r3</th>
              </tr>
            </thead>
            <tbody>
              [Table rows omitted for brevity]
            </tbody>
          </table>
        </div>
        <div></div>
      </div>
    </div>
  </div>
</div>

Answer №2

Custom CSS is not necessary here as there are predefined Bootstrap classes that you can use. Utilize the pre-scrollable and position-fixed classes to add a vertical scrollbar and fix the position of the element.

Check out the updated Jsfiddle demo: jsfiddle

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

Creating a Google Captcha with validation is a straightforward process that can enhance the

I am having issues with adding Google Captcha to my form. Despite all fields working properly, the Captcha integration seems to be causing some disruptions. I have included my code below. Thank you in advance for your help. Please also check the following ...

What is the best way to ensure my images are centered when transitioning to full screen mode?

While working on my site with a grid of images, I noticed that the h1 element centers itself when I go into full screen mode, but the grid of images does not. It seems like the grid is not responsive. How can I ensure that the grid of photos stays centered ...

What are the steps to configure Bootstrap for optimal performance?

Here is the code snippet: <template lang="pug"> b-container b-row b-col h1 strong LICOTA® — ПРОФЕССИОНАЛЬНЫЙ ИНСТРУМЕНТ ВЫСШЕГО КЛАССА ДЛЯ АВТОСЕРВИСОВ И ПРОМ ...

The CSS Bootstrap 4 class 'input-group-append' is not functioning properly. Just recently, the styles were displaying correctly

My web application using AngularJS 1.7.8, jQuery 3.3.1, Bootstrap 4.3.1, and various other CSS and JS libraries worked seamlessly last week. However, today I noticed an issue with the button visualization. To Replicate: Visit openskymap.org to see my d ...

Making use of CSS to manipulate the placement of images within a grid

I've been struggling to insert an image into a grid, and it's causing some issues for me. Currently, the main problem I'm facing is that it's pushing another grid item down. body { padding: 0; margin: 0; } .main { wi ...

Distinct headings break up two-columned lists

Is there a way to ensure that the h2 header always stays with its list items, even if the number of list items varies? Currently, the header appears in one column and the lists appear in another column, causing them to be separated when the list count chan ...

Exploring the World of MVC 4: Delving into Modal Windows, Partial Views,

I am currently utilizing MVC4 along with Entity Framework to build a web application. Within my database, I have a table listing all the individuals. Each person can have their information edited through a modal window that is implemented as a Partial View ...

Embed video with a custom thumbnail in an iframe

Hello everyone! I'm a first-time user on stackoverflow seeking some help. Currently, I am using Dreamweaver to work with HTML and CSS in order to build a website. My task involves sourcing a video from a television archive and embedding it onto my si ...

Challenge in creating a responsive layout using Bootstrap framework

I'm working with Bootstrap, but I'm struggling to achieve the desired layout. My goal is to have the design adapt like this on different screen sizes: ---------------------- Headline | | | image | ----------| | B ...

How to prevent selection of specific months in Bootstrap datepicker

I've been attempting to disable specific months in a datepicker using the datesDisabled option. Even though the documentation states that it should work by passing an array of strings, I haven't been able to make it function properly. Here' ...

What is the best way to align content in the middle of a containing div?

I am struggling with centering text and images inside a div that is 190px x 190px. Despite searching on various platforms, including SO and Google, I have not found a simple solution. Can someone please provide guidance on the easiest way to achieve verti ...

Is there a way to align these buttons in the middle?

I am currently designing a webpage at The challenge I'm facing is: How can I center those buttons on the page? They need to remain centered and responsive even when the page is resized. Additionally, the spacing between the buttons is inconsistent. ...

How can I center two div buttons within a bootstrap column?

My issue is as follows: I currently have two circles stacked on top of each other, but I would like to position them side by side. Below is the HTML for the existing layout: <div class="col-lg-6"> <div class="page-scroll" style="text-align:c ...

Optimizing React and Bootstrap for Maximum Website Design Impact

This is my debut in creating a website using React. I am contemplating on implementing Bootstrap's grid system, but uncertain of the ideal scenarios for its usage and to what extent. Should the grid system be primarily utilized in App.js and within e ...

Center and justify image inside flexbox using MUI

Can someone explain why my image appears centered but not justified? I'm feeling confused about this. <Box sx={{ display: 'flex', minHeight: '100vh', alignItems: 'center', flexGrow ...

Hover shows no response

I'm having trouble with my hover effect. I want an element to only be visible when hovered over, but it's not working as expected. I've considered replacing the i tag with an a, and have also tried using both display: none and display: bloc ...

Organizing Checkbox Groups for Validation in Bootstrap

My form consists of 2 checkboxes and I only want to submit the form if at least one checkbox is checked. The current code requires both checkboxes to be checked, but I tried grouping them using the name attribute without success. How can I group checkbox ...

finding the source file or code where a particular html element is being generated

In the HTML file I have, there are multiple JavaScript files added. Whenever I run the HTML file, a title tag is automatically created in my HTML file. I do not want this title tag to appear in my HTML file. How can I prevent this from happening? Or how c ...

Problem with the overflow setting of a specific div

My website is currently hosted on a test server at medexcel.comeze.com. However, I am encountering an issue where the overflow of the top div is no longer hidden when I hover over a menu button in the top bar. This results in the bottom right corner of th ...

Secret message concealed within the depths of my Bootstrap 5 Side Navbar

I have successfully created a side NavBar using Bootstrap 5, but I'm facing an issue where my text is getting hidden behind the navbar. Any suggestions on how I can resolve this? Below is the code for my side Navbar: const Navbar = ({ handleClick, is ...