Troubleshooting problem with scrollbar in HTML table within a div element

I'm utilizing Bootstrap for the majority of my CSS. I've split a section into two columns, with the left column displaying a table with data and the right side featuring a Google map. The issue arises when the table row grows, as it doesn't naturally display a scrollbar. Despite my attempts to control the scrollbar using CSS, it's not functioning properly, as depicted in the image. https://i.sstatic.net/AhzFc.png

There are two main problems with the scrollbar. First, it's far from the actual table, which I assume is due to setting the scrollbar on the parent div container. Second, when trying to scroll using the mouse wheel, the table starts flickering. I'm struggling to find a solution to this issue. Here is the code snippet:

HTML Part

I've omitted irrelevant sections.

<main class="flex-shrink-0">
        <div class="container" style="max-width: 100% !important;">

            <section>

                <div class="row">
                    <div class="col">
                        
                        <div class="container" style="overflow-y:auto;overflow-x:auto;;height:400px;width: 100%;">
                            <table class="" width="100%" style="overflow:auto;height:400px;width:100%;">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>Code</th>
                                        <th>Size</th>
                                        <th>Illumination Type</th>
                                        <th>Location</th>
                                        <th>Availability</th>
                                        <th>Media</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for hoarding in road_hoardings %}
                                    <tr>
                                        <td>{{forloop.counter}}</td>
                                        <td>{{hoarding.site_code}}</td>
                                        <td>{{hoarding.size}}</td>
                                        <td>{{hoarding.illumination_type}}</td>
                                        <td>{{hoarding.location}}</td>
                                        <td>{{hoarding.available_by_date}}</td>
                                        <td>
                                            <button class="btn btn-primary">
                                                <i class="far fa-images"></i>
                                            </button>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="col">
                        <div id="map" style="width: 100%; height: 100%;"></div>
                    </div>
                </div>

            </section>

        </div>
    </main>

Table Related CSS

body {
            /* overflow-x: hidden; */
            margin: 0;
            background: linear-gradient(45deg, #49a09d, #5f2c82);
            font-family: sans-serif;
            font-weight: 100;
        }


        table {
            width: 800px;
            /* height: 400px; */
            /* border-collapse: collapse; */
            /* overflow: hidden;
            overflow-y: auto; */
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
        }

        th,
        td {
            padding: 15px;
            background-color: rgba(255, 255, 255, 0.2);
            color: #fff;
        }

        th {
            text-align: left;
        }

        thead th {
            background-color: #55608f;
        }

        tbody tr:hover {
            background-color: rgba(255, 255, 255, 0.3);
        }

        tbody td {
            position: relative;
        }

        tbody td:hover:before {
            content: "";
            position: absolute;
            left: 0;
            right: 0;
            top: -9999px;
            bottom: -9999px;
            background-color: rgba(255, 255, 255, 0.2);
            z-index: -1;
        }

Answer №1

The container and table have been modified to include height and overflow properties:

<div class="container" style="overflow-y:auto; overflow-x:auto; height:400px; width:100%;">
    <table class="" width="100%" style="overflow:auto; height:400px; width:100%;">

However, the unnecessary overflow and height properties in the table can be removed to simplify the code:

<table class="" width="100%" style="width:100%;">

A refined version of your code can be found below in a full-screen view for optimal results.

body {
            /* overflow-x: hidden; */
            margin: 0;
            background: linear-gradient(45deg, #49a09d, #5f2c82);
            font-family: sans-serif;
            font-weight: 100;
        }


        table {
            width: 800px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            position: relative;
            overflow: hidden;
        }

        th,
        td {
            padding: 15px;
            background-color: rgba(255, 255, 255, 0.2);
            color: #fff;
        }

        th {
            text-align: left;
        }

        thead th {
            background-color: #55608f;
        }

        tbody tr:hover {
            background-color: rgba(255, 255, 255, 0.3);
        }

        tbody td {
            position: relative;
        }

        tbody td:hover:before {
            content: "";
            position: absolute;
            left: 0;
            right: 0;
            top: -9999px;
            bottom: -9999px;
            background-color: rgba(255, 255, 255, 0.2);
            z-index: -1;
        }
<main class="flex-shrink-0">
        <div class="container" style="max-width:100% !important;">

            <section>

                <div class="row">
                    <div class="col">
                        
                        <div class="container" style="overflow-y:auto; overflow-x:auto; height:400px; width:100%;">
                            <table class="" width="100%" style="width:100%;">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>Code</th>
                                        <th>Size</th>
                                        <th>Illumination Type</th>
                                        <th>Location</th>
                                        <th>Availability</th>
                                        <th>Media</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <!-- Table rows go here -->
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="col">
                        <div id="map" style="width:100%; height:100%;"></div>
                    </div>
                </div>

            </section>

        </div>
    </main>

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

Positioned footer without predetermined height

I am having trouble with positioning the footer so that it always stays at the bottom of the page. When there is not enough content on the page, the footer does not reach the bottom as desired. Additionally, the footer does not have a fixed height. Below i ...

Styling a numerical value to appear as currency with CSS

Is there a way to style the content of an element as currency using just CSS? It would be great to know if we can control how the value is displayed with CSS. I haven't found anything yet, so not getting my hopes up :) <!DOCTYPE html> <html& ...

Looking for a Plugin that Can Responsively Display Images in a Vertical Layout - Does One Exist using Jquery

Looking for a gallery slider plugin that is responsive both horizontally and vertically. Have tried Flexslider1/2, Galleria, and others but they do not adjust to vertical resizing. Changing the CSS did not help. If you resize the browser horizontally with ...

What is the best way to make my background image adapt to different screen sizes

I am currently working on updating my webpage and facing a few challenges that I would appreciate some assistance with: One issue is that the images on my page do not adjust to the size of the browser window. As a result, when I resize the window, the i ...

Setting up global color variables for React with Material UI theming is essential for ensuring consistent and

Is there a way to customize the default material-ui theme using global CSS? Additionally, how can we incorporate HEX values for colors when setting primary and secondary colors in the theme? In my App.js root file, I have defined a custom theme and want t ...

How can you change the alignment of items from vertical to horizontal using Bootstrap?

I'm looking to create a responsive layout similar to the design of duckduckgo.com. This page features a logo, the DuckDuckGo brand name in text form, and a search box. When I reduce the width of the browser window to nearly horizontal bar size, the th ...

Unable to extract property from object in context due to its undefined status

Having trouble with the useContext hook in my React app for managing the cart state. Keep getting an error stating that the function I'm trying to destructure is undefined. I'm new to using the context API and have tried various solutions like e ...

Guide: Using jQueryUI's explode effect to animate an HTML element explosion

I'm having trouble getting the jQueryUI explode effect to work properly. I've tested it out on this jsfiddle, but the explosion effect doesn't seem to happen as expected - the element just disappears with no explosion animation. $('h1, ...

Elevate column to top position in mobile display with Bootstrap

I am currently working with Bootstrap column classes and have set up four columns as follows: <div class="col-md-3"> @include('schedulizer.classes-panel') @include('schedulizer.time-span-options-panel') @include(&apos ...

Struggling to display the sorted array items on the screen?

Within the realm of my jsfiddle experiment, my aim is to organize items based on price from highest to lowest by utilizing the following function: function mySortingFunction() { var elements = [].slice.call(document.getElementsByClassName("price")); e ...

JavaScript appending checkboxes to a list not functioning as expected

I have not been using jQuery, JavaScript, and HTML to create a list of products. The task I am working on now is the ability to select multiple items from this list. Currently, the HTML list is dynamically populated with <li> elements using JavaScri ...

The key to highlighting the search terms in bold format

How can I highlight the search terms entered by users in the search box? I want all keywords in every search result to be bolded. For example, when a search term is entered and the results page displays all results with the typed term in bold within each ...

Omit the element from the event listener

Is there a way to prevent the image from triggering a click event in this code snippet? $('#templtable .trhover *:not(#infoimg)').live('click', function(event) { event.stopPropagation(); $(this).toggleClass('selected&a ...

Develop a fresh button using either JavaScript or PHP

I have designed a mini cart (drop down) on my WordPress site with different styles for when there are products and when empty. To enhance the design, I have utilized CSS pseudo elements before and after to add content dynamically. Is it possible to includ ...

What is the method to deactivate child elements within an element that possesses the disabled attribute in Polymer?

What are some effective methods for disabling children elements when at least one parent element is disabled? I have a form with nested groups and fields that can be disabled based on certain conditions. Different parent elements may be disabled independe ...

Clicking outside of a focused div does not trigger a jQuery function

Check out this HTML snippet: $html .= " <td><div class='edit_course' data-id='{$id}' data-type='_title' contenteditable='true'>{$obj->title}</div></td>"; Next, see the jQuery code below: ...

Auto-scrolling text box cursor movement

My query is quite similar to the topic discussed in this thread on automatic newline in textarea. However, my situation involves multiple textareas with a 1-row attribute, making it seem like writing on air due to the absence of visible borders (I've ...

Is there a way to retrieve the aria-label attribute value from this specific WebElement?

When utilizing Java Selenium, I have access to a WebElement object that corresponds to the following HTML node: <td role="gridcell" class="mat-calendar-body-cell ng-star-inserted" style="width: 25%; padding-top: 7.14286%; paddin ...

Restrict User File Uploads in PHP

I have a system set up that enables users to upload files under 200 MB. Once the file is downloaded once, it will be automatically deleted. Additionally, all files are deleted from the server after 24 hours. I am looking for a way to limit the number of up ...

Struggling to connect HTML with CSS in Hugo

I am experimenting with a pre-fabricated theme in Hugo and incorporating some Bootstrap codes. I want to change the color of all links when displayed or hovered over. Despite searching extensively, I have been unable to achieve this through the use of CSS ...