How can I resolve the issue of 'overflow-x: auto' not functioning on a table within a CSS Grid to enable scrolling for responsiveness?

I'm in the process of designing a new Wordpress theme and am faced with the challenge of revamping the existing tables within the site's content. While most of my alterations to the table have been successful, I'm encountering an issue when trying to make the table horizontally scrollable on mobile devices by adding 'overflow-x: auto' to its container div. Currently, the table adjusts its width according to the viewport size, but once it reaches its minimum width, it remains fixed and causes the entire page to become scrollable.

Despite researching similar queries on stackoverflow, none of the solutions seem to be effective for me. I've enclosed the table within a div container and applied 'overflow-x: auto', but it doesn't produce the desired effect.

EDIT: Interestingly, the code snippet works correctly on StackOverflow, but fails to function on my Wordpress website. Could this be a compatibility issue with Wordpress?

EDIT 2: Even after installing a table plugin, the problem persists. The plugin creator mentioned that the root cause may lie in my usage of CSS Grid's 'grid-column' property, as the table parent is not responsive. This was something I hadn't considered previously, hence it wasn't included in my code initially. I've made the necessary adjustments to reflect my use of CSS Grid, but the issue still persists as displayed in the StackOverflow code snippet.

Answer №1

This question may be from a while back, but the problem stems from utilizing the flexible unit Fr in

grid-template-columns: 10px 1fr 10px;
.

To resolve this issue, consider using an absolute value like

grid-template-columns: 10px calc(100% - 20px) 10px;

Answer №2

Feel free to utilize the following code snippet:

<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <title>Hello, world!</title>
    <style type="text/css">
        html, body {
            margin: 0px;
        }
        table {
            border: 1px solid #000;
            border-collapse: collapse;
            width: 100%;
            border-spacing: 0;
        }
        thead {
            background-color: #efc879;
            font-weight: bold;
        }
        td,
        tr,
        th {
            border: 1px solid #000;
        }
        th,
        td {
            text-align: left;
            padding: 8px;
        }
        th {
            font-weight: bold;
        }
        tr:nth-child(odd) {
            background-color: #ffffff;
        }
        tr:nth-child(even) {
            background-color: #ececec;
        }
        td {
            padding: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div style="overflow-x:auto;">
            <table>
                <tbody>
                    <tr>
                        <td></td>
                        <td>SF</td>
                        <td>CS</td>
                        <td>NM</td>
                        <td>JC</td>
                        <td>JH</td>
                        <td>MT</td>
                        <td>KF</td>
                        <td>TG</td>
                        <td>TOTAL</td>
                    </tr>
                    <tr>
                        <td>Person</td>
                        <td style="background-position: 0% 50%; background-color: black;">XXX</td>
                        <td align="center">0</td>
                        <td align="center">0</td>
                        <td align="center">0(d)</td>
                        <td align="center">0(d)</td>
                        <td align="center">0(d)</td>
                        <td align="center">0(d)</td>
                        <td align="center">1</td>
                        <td align="center">1</td>
                    </tr>
                    <tr>
                        <td>Person</td>
                        <td align="center">1</td>
                        <td style="background-position: 0% 50%; background-color: black;">XXX</td>
                        <td align="center">1</td>
                        <td align="center">1</td>
                        <td align="center">1</td>
                        ...

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

Ensure that the radio button is set to its default option when the user accesses the page

I have a model with a 'PartActionType' enum which includes Transfer, Harvest, and Dispose options. public enum PartActionType { Transfer, Harvest, Dispose } On my view page, I am displaying these options using ...

Tips for customizing the appearance of the <select> <option> element with jQuery or CSS

What are some ways to style the <option> HTML tag, using jQuery or CSS? Any suggestions on styling the <option> tag? ...

Issue encountered: The differ cannot recognize the provided object '[object Object]', which is of type 'object'. NgFor is limited to binding Iterables only

I have been following a tutorial on Ionic created by Paul Halliday, focusing on a shopping list project that utilizes Firebase and Angular. However, I am encountering an error every time I try to run the application: Error: Uncaught (in promise): Error: ...

PHP Error: Sound Reflection

My HTML code is quite lengthy and I am using the echo function to display it. However, I am encountering an error. Interestingly, when I remove the problematic code snippets highlighted by the error messages, a new error appears in the body section of the ...

Ways to delete an image from a batch file uploading feature

I encountered an issue with my multiple image upload function that includes preview and remove options. When I select 4 images and preview them correctly, removing 2 from the preview still results in uploading all 4 images to the database. $(document).rea ...

Relocate the form element from its current position inside the form, and insert it into a different div

I have a sidebar on my website with a search/filter form. I am attempting to relocate one of the elements (a sort order dropdown) from this form, outside the form using CSS/JS and display it inside a div on the right side. Is it possible to do this without ...

What is the method for retrieving information from a JSON file that has been uploaded?

I am working with some HTML code that looks like this: <input type="file" id="up" /> <input type="submit" id="btn" /> Additionally, I have a JSON file structured as follows: { "name": "Jo ...

Slideshow elements removed

I attempted to remove my links individually from the div id="wrapper", but unfortunately have encountered an issue while doing so: window.onload = function () { setInterval(function () { var wrapper = document.getElementById("wrapper"); var my_l ...

Issue with ngShow not functioning when used within an HTML template

I'm struggling with displaying and hiding a div from a template on an HTML page. You can see a simple JSFiddle example here. app.directive('example', function () { return { restrict: 'E', template: '< ...

Is it possible to utilize CSS to generate a full-width slider while maintaining the aspect ratio of the content?

I am currently utilizing the unslider plugin to design a full-width slider header on a webpage (). Although it functions well at the dimensions I set it up for (1920x450), issues arise when viewed on different screen resolutions. See below: The background ...

Experience the full functionality of Google Maps API without the need for jQuery or PHP with PanTo

I'm not a developer and I find myself stuck in the panTo() function. All I want is to execute this function with an if-else statement without having to reload the Google Map or using jQuery. <body> <div id="map"></div> <d ...

How can CSS grids adapt to different screen sizes and resolutions?

Currently experimenting with Unsemantic for responsive grids in CSS, but struggling to comprehend how it can effectively handle various resolutions like 400, 768, and 1024 with just two classes: grid-XX and mobile-grid-XX. The Unsemantic CSS files contain ...

The initial item on the list, displayed on the right side in Google Chrome

Currently experiencing an issue with Google Chrome where the first list item's bullet is floating right while all other list items' bullets are aligned correctly at left. Here is the code snippet causing the problem: <div class="window_sub_ ...

Troubleshooting problems with a JavaScript game that involves guessing numbers

I have been given a challenging Javascript assignment that involves using loops to create a counting betting game. The concept is simple: the User inputs a number, and the computer randomly selects a number between 1 and 10. The User can then bet up to 10 ...

Inline-block styling behaving incorrectly within span element

I am facing an issue with aligning a validation message inline with a textbox in my HTML code. Despite trying various options, the validation message appears just below the textbox instead of beside it. Below is the snippet of the code in question: HTML ...

Pushing down menu items in a dropdown CSS navigation bar

I have a vertical navigation menu with parent and non-parent items. I want the parent items to display their child pages when hovered over, while also pushing down the items above them. HTML: <nav class="main"> <ul> <li> ...

The dilemma of calculating the total width of jQuery's list items

I am in the process of creating a submenu that should look like this: HTML: <ul class="mainMenu clearfix"> <li><a href="#">Eurodan huset</a></li> <li><a href="#">Hustyper</a></li> <li&g ...

Ways to align the `<ol>` number at the top vertically

I'm having trouble aligning my <ol> numbers vertically at the top of the list. I've created a sample on CodePen. ol { list-style-type: decimal-leading-zero; font-size: 11px; } a { font-size: 80px; tex ...

"Encountering a 405 error when transmitting information from an HTML file to a Python Flask server using 'GET / HTTP/1.1'

As someone who is brand new to the world of python and AJAX, I have been piecing everything together from various sources online including examples and Flask documentation. So far, I have managed to make some progress. My goal is to send latitude and longi ...

Is there a callback or event that can be used to ensure that getComputedStyle() returns the actual width and height values?

Currently, I find myself in a situation where I need to wait for an image to load before obtaining its computed height. This information is crucial as it allows me to adjust the yellow color selector accordingly. Question: The process of setting the yello ...