What could be the reason behind this HTML table behaving responsively on a desktop view but not on a mobile view

My goal is to create an HTML table that will display the td's in a stacked, card-like form when viewed on mobile devices.

While it works correctly on a narrow desktop screen, the problem arises when viewing it on mobile.

I've realized that the viewport setting is essential but hasn't resolved the issue.

Are there any other suggestions?

I've tried multiple tutorials and codePens claiming to provide code for a "mobile-friendly cards style responsive table", but unfortunately, none of them work on real mobile devices tested on iOS 12 Safari or Chrome.

In the best-case scenario, the table appears unusual; in the worst case, it remains horizontal.

<style>
body {
  font-family: "Open Sans", sans-serif;
  line-height: 1.25;
}
...
</style>
<html>

    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link async href="./style.css" rel="stylesheet" type="text/css" media="screen, projection"/>
    </head>

    <body>
        <table>
         <caption>Documents Details</caption>
         <thead>
          ...
         </tbody>
        </table>  
    </body>

</html>

My expectation was for the table rows to stack vertically like cards on mobile, but this isn't happening. Surprisingly, it works fine on desktops.

Here's a JsFiddle.

What do you think could be causing this issue?

Answer №1

After closely examining the code in JsFiddle, I decided to reverse-engineer it by systematically removing parts until I discovered the root of the problem: the absence of <!DOCTYPE HTML> at the beginning of the HTML document.

What a headache.

But, problem solved!

Answer №2

The issue at hand is likely stemming from improperly formatted HTML, specifically the placement of the <div> right after the opening <html> tag. Upon inspecting the DOM tree, it seems that elements within the <head> are getting nested inside the <body>. While I haven't tested this myself, removing the problematic div and its closing counterpart following the </body> tag could potentially resolve the issue. Alternatively, relocating those divs within the <body> itself might also do the trick.

Based on the link provided in your comment, it appears that the code there differs from what was shared above.

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

Locating the save directory with fileSystem API

I've been working on saving a file using the fileSystem API. It appears that the code below is functional. However, I am unable to locate where the saved file is stored. If it's on MacOS, shouldn't it be in this directory? /Users/USERNAM ...

Troubleshooting Date Problems in Angular

When using the HTML5 date picker, I have encountered an issue where after choosing a date, the ng-model displays an older date instead of the current one selected. <input type="date" ng-model="dateModel" /> For example, when selecting the current d ...

How to integrate VLC media player into an HTML webpage

I'm currently struggling to incorporate a VLC player into a website. What is the most effective method to achieve this task? I need to stream a video file using VLC and display it on the webpage for other users who are logged into my site to view. I&a ...

The PHP code to include the head section with a link to the CSS is not functioning properly

I've recently dabbled in PHP and encountered my first issue that I can't seem to resolve. My goal is to have my index.php file, with the following code in the head section: <head> <?php require 'php/main/head.html'; ?> & ...

Navigating to a new webpage element within a div class using Selenium

Struggling with selecting an element on a webpage using Selenium? Despite my experience with this website and methods like css selector and XPath, I can't seem to pinpoint the element in a troublesome section. The challenge arises when I attempt to in ...

Using Ajax to make a request on the same page but specifically within a column

I'm currently experimenting with AJAX to display live CSV data on my website. Right now, the AJAX script triggers on button click, but what I really want is for the data to be shown in a grid view without requiring a refresh or clicking a button. Howe ...

Error encountered in jQuery's addClass and removeClass functions: Unable to read the property 'length' of an undefined value

Upon loading my page, I aim to have some of the div elements hidden initially and display only one. Here is a script that accomplishes this goal: <script> $(document).ready(function () { $(".total").click(function () { $("#pi ...

Utilizing PHP to dynamically load HTML forms and leveraging JQuery for form submissions

I am currently facing a dilemma that I am unsure how to approach. It seems that JQuery requires unique ID's in order to be called in the document ready function. I use PHP to read my MySQL table and print out HTML forms, each with a button that adds a ...

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: ...

The browser is capable of detecting multiple key presses using JavaScript

I'm attempting to trigger an action when certain keys are pressed simultaneously. The keys I need to detect are bltzr, but my browser only registers bltz without the final r. I've tried this on both Windows and OSX, but still can't capture ...

How can I showcase the Junit HTML report in Karate DSL, as outlined in the official Karate documentation?

After following the Karate Doc and pasting the Junit HTML Report into my browser, I was surprised to see that the output was in plain text and did not look anything like what was described in the tutorial video. I attempted to view it on both Firefox 57.0. ...

Is it possible to turn off the fallback color for bourbon radial gradients?

Is there a way to prevent the fallback from being applied when using the radial gradient mixin in Bourbon? I've consulted the documentation at , which states that the fallback is optional. However, no matter what I attempt, it seems that the primary ...

Issue with deploying responsive background image on Github platform

My responsive background image isn't displaying properly on mobile devices after I deployed my project to Github. Although it appears correctly under the Google Chrome inspect mobile tool, when accessed live on a mobile device, the image covers the ba ...

Issues with Bootstrap-slider.js functionality

I'm having trouble getting the bootstrap-slider.js library from to function correctly. All I see are textboxes instead of the slider components. You can view an example at I have verified that the CSS and JS files are pointing to the correct direc ...

issue with excessive content overflow

I'm working with a div structure where the outer div has the following CSS properties: position: relative; overflow: hidden; min-heigth: 450px; Inside this outer div, there is another div with the following CSS properties: position: absolute; top: ...

obtain the equivalent offsetX value for touch events as for mouse events

Greetings! I am currently attempting to retrieve the offsetX and Y values of a touch event, which ideally should match the offsetX value of a mouse event. In order to achieve this, I have implemented the following code: ev.offsetX = ev.targetTouches[0].p ...

Angular UI-Router: Customizable template for dynamic content

My goal is to dynamically load a navbar based on the user, but I am facing difficulties accessing my $rootScope. $stateProvider /*Login*/ .state('login', { url: '/', data: {pageTitle: 'Sign in.'}, ...

Attempting to position items within a container

Currently, I am in the process of creating a list of job opportunities to be displayed on a side bar of our careers page. Each job listing should include the job title along with an apply button enclosed within a rounded grey box that allows for some spaci ...

Scrolling to the bottom of the page triggers jQuery to load additional content

Is your jQuery script not working properly when attempting to load more content upon reaching the bottom of the page? It seems to be functional on Safari/iPad and Android Mozilla browsers, but encountering issues on default Android and Chrome browsers. ...

Registering a change event for a table's value

I am a beginner in Angular and struggling with writing an event that can successfully pass the changed value from a table cell to my component. Below is the HTML code for the table cell, where the user should be able to change the value and have it passed ...