Adjust the table height to 25% and include a vertical scrollbar using Bootstrap styling

I have been working on designing a web page layout that includes two status tables positioned side by side at the top. While I have successfully set this up, I am facing an issue with implementing a vertical scroll feature specifically for the right-hand table.

The goal is to ensure that both tables collectively occupy no more than 25% of the viewport height, with only the right table having a vertical scroll bar in case the data exceeds this limit (while keeping the left table compact). This setup is necessary as additional elements will be added below the tables on the page.

Although I managed to get a vertical scrollbar working by manually setting a specific pixel height for the table, my aim is to make it responsive to different screen sizes without fixed dimensions.

My current webpage incorporates Bootstrap 5 and jQuery 3.6.

To demonstrate, here is an attempt at achieving this layout. You can also refer to this fiddle

HTML

<div class="page-body">
  <div class="container-fluid h-25">
    <div class="row justify-content-around h-25">

      <div class="col">
        <table class="table table-bordered table-hover">
          <thead>
            <tr>
            <th colspan="2" style="text-align:center">System Status</th>
            </tr>
            <tr>
            <th>Active Jobs</th>
            <th>Queued Jobs</th>
            </tr>
          </thead>
          <tbody>
            <td></td>
            <td></td>
          </tbody>
        </table>      
      </div>

    <div class="col overflow-scroll">
    <table class="table table-bordered table-hover">
      <thead>
        <tr>
          <th colspan="3" style="text-align:center">Recently Executed Tasks</th>
        </tr>
        <tr>
          <th>Job</th>
          <th>Task</th>
          <th>Start Time</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Job B</td>
          <td>Task X</td>
          <td>06.06.2022 15:31:17</td>
        </tr>
        ...many more rows...
        <tr>
          <td>Job B</td>
          <td>Task X</td>
          <td>06.06.2022 15:31:17</td>
        </tr>
      </tbody>
    </table>
    </div>

   </div>
 </div>
</div>

CSS

.page-body {
  width:100vw;
  height:100vh;
}

Despite my efforts to restrict the tables to 25% of the viewport, they end up expanding to fill the entire page. Any suggestions on how to resolve this?

Answer №1

If you want to enable vertical scrolling, ensure that the parent element has a fixed height specified in CSS, for example: style="height:200px;". Your HTML code should resemble the following structure:

<div class="page-body">
  <div class="container-fluid h-25">
    <div class="row">

      <div class="col-md-6 overflow-scroll" style="height:200px;">
        <table class="table table-bordered table-hover">
          <thead>

          </thead>
          <tbody>

          </tbody>
        </table>      
      </div>

      <div class="col-md-6 overflow-scroll" style="height:200px;">
        <table class="table table-bordered table-hover">
          <thead>

          </thead>
          <tbody>

          </tbody>
        </table>
      </div>
      
    </div>
  </div>
</div>
      

If you're interested in advancing your skills in Web development, feel free to explore my Web Programming Course.

Thank you!

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

Unlimited scrolling feature in Ionic using JSON endpoint

Trying to create an Ionic list using data from a JSON URL. JSON Code: [{"id":"1","firstName":"John", "lastName":"Doe"}, {"id":"2","firstName":"Anna", "lastName":"Smith"}, {"id":"3","firstName":"Peter", "lastName":"Jones"},{......................}] app.j ...

Text will not be displayed when it is written on images

I'm currently facing a challenge with adding text onto two different images, one on the left and one on the right. I have included HTML and CSS code but it seems to be incorrect. Can someone please help me fix it? #container { width: 400px; hei ...

Scroll overflow can be hidden

I'm working on a project with a div containing scrollable content, but I'm struggling to get the header to overflow its parent element. It seems that using overflow: scroll is causing the element to have overflow: hidden as well. Any assistance ...

What could be causing render_template to fail when attempting to update the same parameters more than once?

Lately, I've dived into the world of Flask, MongoDB, and ElasticSearch. So far, my MongoDB and ElasticSearch setups are running smoothly. However, I've encountered an issue with generating a list of dictionaries and displaying them on my HTML we ...

Responsive design element order rearrangement

My code example is as follows: <div class="info-container"> <span class="item1">item1</span> <a class="item2" href="#">item2</a> <a class="item3" href="#">item3</a> </div> I want to rearran ...

Easiest and quickest method to retrieve metadata from a website

Currently, I am using preg_match to extract the 'title' from websites, however, it is loading very slowly. Here is what I have so far: This code sends links to a function: <?php foreach($savedLinks as $s) { echo "<div class='sa ...

Guide on how to showcase the chosen option of a dropdown menu in a table by clicking an arrow icon

I am looking to modify the code below so that instead of pushing data to the selected panel, it pushes data to a table inside the panel. The new data should be added to a new row every time the arrow is clicked. <html> <head> <title>Bo ...

Having trouble establishing a connection with the C# Controller when processing the frontend request

Having trouble implementing the Search by siteId functionality using typescript and C#. The issue arises when trying to connect to the C# controller from the frontend request. The parameter I need to pass is siteId. Below is the code snippet: HTML: ...

What is the best way to insert a tagline above a form?

I'm struggling to figure out where to place a tagline above my form. I want it to be neat and clean, but haven't been successful in finding the right spot. I attempted to insert an <h2> inside the form, but it doesn't look good at al ...

Error: Element not found. Element with the specified XPath query '//button[normalize-space()='LOAD MORE']' could not be located

My current project involves creating a web scraper that is designed to continuously scroll down a page until it locates the "Load More" button and then clicks on it. However, I am encountering an issue where the program is unable to find the specified butt ...

What other function can I combine with the foreach function?

I am working on populating the empty array named $Errors with specific items to enforce restrictions on my file upload form. My approach involves adding a <div> element as an item within the array, containing certain strings. I aim to concatenate t ...

Struggling with using flexboxes and creating animated elements

Seeking assistance with animating the search bar on a website project. The animation is functioning, but the search input abruptly moves when the animation starts, as shown in this GIF: https://i.sstatic.net/17sFl.gif I am utilizing jQuery for the animat ...

PHP: the images uploaded are not located within the designated folder

Having trouble uploading multiple images to a folder and saving them in the database? The images are not moving to the folder, even though the code works on localhost. Here is the code snippet: var abc = 0; // Declaring and defining global incremen ...

Creating custom components in React

At times, I find myself in need of a special UI component such as a multiple range slider. However, I have a preference for not relying on third-party libraries, so I usually opt to create the component myself. As time has passed, I have completely stopped ...

Using Javascript to display or conceal a specific child element within a loop, based on which parent element has been clicked

I need assistance with creating a grid of projects where clicking on a specific 'project' in the loop will display the corresponding 'project_expanded' div, while hiding all other 'project_expanded' divs. My initial plan was ...

Vue 3 project experiencing issue with Bootstrap 5 tabs failing to update upon tab click

Currently, I'm in the process of developing a vue3 application with bootstrap 5. As part of this project, I am implementing tabs. Although I can successfully click on the tabs, I have encountered an issue where the tab-content remains fixed on the ini ...

Prevent Scrolling of Body Content within a Specified Div

In my current situation, I am dealing with a large number of divs (over 300) that are being used as part of an interactive background. The issue arises when viewing the page on mobile versus desktop – there are too many divs on desktop, causing excessive ...

Personalizing Google Map pin

I found some code on Codepen to add pointers to a Google map. Currently, it's using default markers but I want to change them to my own. However, I'm not sure where in the code to make this update. Any examples or guidance would be appreciated. ...

What is the correct way to horizontally center a Material icon within a div?

How do I correctly center a Material Design icon within a div to fix the gap issue? I have tried using text-align on the items div, but it hasn't worked. (Refer to screenshots for clarification) https://i.sstatic.net/eHuiR.png https://i.sstatic.net/nL ...

Could someone provide a detailed explanation on the functionality of multiple inline nth-child() in CSS?

In this scenario, there is an example provided: html>body>#wrapper>div>div>div:nth-child(1)>div:nth-child(1)>nav { I am curious about the functionality of this code. Could someone dissect each div, ">", and nth-child()? Your ins ...