What is hindering the responsiveness of this HTML table?

I recently designed a schedule table that resizes properly in the browser, but when I tried to access it on my mobile phone, it didn't resize correctly. On my phone screen, half of Thursday was cut off due to the horizontal scroll.

https://i.sstatic.net/kA70L.png

Despite my best efforts, I can't seem to figure out why this issue is happening. As someone relatively new to coding, my code might not be the cleanest. Can anyone identify the problem or suggest any tweaks?

Your assistance would be greatly appreciated.

body {
  font-family: proxima nova;
}

th,
td {
  text-align: center;
  border-collapse: collapse;
  outline: 1px solid #e3e3e3;
}

td {
  padding: 1% 2%;
}

th {
  background: #44A499;
  color: white;
  padding: 1% 2%;
}

td:hover {
  cursor: pointer;
  background: #44A499;
  color: white;
}
<table width="100%" align="center">
  <div id="head_nav">
    <tr>
      <th>Time</th>
      <th>Monday</th>
      <th>Tuesday</th>
      <th>Thrusday</th>
    </tr>
  </div>

  <tr>
    <th>16:15 - 17:45 </th>

    <td>
      <!--<div class="content"><span class="hidden"></span>-->Gentle Yoga at the Dragon Theater, Barmouth. </td>
    <td>Gentle Yoga at Calon Lan Yoga Studio, Penrhyndeudraeth.</td>
    <td title="No Class" class="Holiday"></td>


    </div>
  </tr>

  <tr>
    <th>18:00 - 19:45</td>

      <td>Dynamic Yoga at the Dragon Theater, Barmouth.</td>
      <td>Dynamic Yoga at Calon Lan Yoga Studio, Penrhyndeudraeth.</td>
      <td>Ashtanga Flow Yoga at Calon Lan Yoga Studio, Penrhyndeudraeth.</td>


      </div>
  </tr>


  </div>
  </tr>
</table>

Answer №1

After reviewing the code, I identified and corrected a few errors. The unnecessary divs in the table were removed, as well as fixing issues such as a <th> tag mistakenly closed with a </td> tag and some repeated closing tr tags. Everything seems to be working correctly now. To improve the readability of the table, I would recommend following the suggestion from w3schools by adding a container element - for example, a <div> - with a CSS style of overflow-x:auto. This will ensure that a horizontal scrollbar is displayed if the content exceeds the screen width.

If you want more information on creating responsive tables, you can visit w3schools' page "How TO - Responsive Tables" at: https://www.w3schools.com/howto/howto_css_table_responsive.asp

Below is the revised code without the unnecessary <div> elements and with the corrected <th> tag. This version has been tested on Safari on an iPhone 5s:

<head>
<title>Yoga Classes</title>
<style type="text/css">
    body {
        font-family: proxima nova;
    }
    th,td {
        text-align: center;
        border-collapse: collapse;
        outline: 1px solid #e3e3e3;
    }
    td {
        padding: 1% 2%;
    }
    th {
        background: #44A499;
        color: white;
        padding: 1% 2%;
    }
    td:hover {
        cursor: pointer;
        background: #44A499;
        color: white;
    }
    </style>
</head>
<body>
<table width="100%" align="center" >
    <tr>
        <th>Time</th>
        <th>Monday</th>
        <th>Tuesday</th>
        <th>Thursday</th>
    </tr>
    <tr>
        <th>16:15 - 17:45 </th>
        <td>Gentle Yoga at the Dragon Theater, Barmouth.</td>
        <td>Gentle Yoga at Calon Lan Yoga Studio, Penrhyndeudraeth.</td>
        <td title="No Class" class="Holiday"></td>
    </tr>
    <tr>
        <th>18:00 - 19:45</th>
        <td>Dynamic Yoga at the Dragon Theater, Barmouth.</td>
        <td>Dynamic Yoga at Calon Lan Yoga Studio, Penrhyndeudraeth.</td>
        <td>Ashtanga Flow Yoga at Calon Lan Yoga Studio, Penrhyndeudraeth.</td>
    </tr>
</table>
</body>

Answer №2

Correct the code structure and set a maximum width of 300px for the body element to showcase.

body {
  font-family: proxima nova;
  width: 300px;
}

th,
td {
  text-align: center;
  border-collapse: collapse;
  outline: 1px solid #e3e3e3;
}

td {
  padding: 1% 2%;
}

th {
  background: #44A499;
  color: white;
  padding: 1% 2%;
}

td:hover {
  cursor: pointer;
  background: #44A499;
  color: white;
}
<table width="100%" align="center">
  <thead>
    <tr>
      <th>Time</th>
      <th>Monday</th>
      <th>Tuesday</th>
      <th>Thrusday</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>16:15 - 17:45 </th>

      <td>
        <!--<div class="content"><span class="hidden"></span>-->Gentle Yoga at the Dragon Theater, Barmouth. </td>
      <td>Gentle Yoga at Calon Lan Yoga Studio, Penrhyndeudraeth.</td>
      <td title="No Class" class="Holiday"></td>
    </tr>

    <tr>
      <th>18:00 - 19:45</th>

      <td>Dynamic Yoga at the Dragon Theater, Barmouth.</td>
      <td>Dynamic Yoga at Calon Lan Yoga Studio, Penrhyndeudraeth.</td>
      <td>Ashtanga Flow Yoga at Calon Lan Yoga Studio, Penrhyndeudraeth.</td>
    </tr>

  </tbody>
</table>

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

Looking for assistance with CSS to properly align a dozen items

UPDATE: See the current layout in this JFiddle based on feedback received from others, still a few tweaks needed. In my setup, there are 12 divs housed within one container div. These 12 divs consist of 6 text components and 6 corresponding input fields. ...

Using Placeholder Attribute in HTML5 Inside Struts HTML:text Tag

In the web application I am developing with Struts 1.3.10, I would like to add placeholders to my textfields. However, the current Struts taglib does not support this feature and I prefer not to rely on JavaScript for implementation. Are you aware of any ...

Issue with pop-up functionality on web page using HTML, CSS, and JavaScript

Recently, I created a unique popup using HTML. You can see the complete code (excluding CSS) here: https://codepen.io/nope99675/pen/BawrdBX. Below is the snippet of the HTML: <!DOCTYPE html> <html> <head> <meta charset=&quo ...

Using PHPMailer to send an HTML page via email

I am attempting to email this HTML page using unlayer.com. I have tried using $mail->isHtml(true), ... msgHtml... but the email client keeps showing the code instead of the HTML page. Any suggestions on how to fix this? Here is my code: $sql = "SE ...

Using a JSON file as a database for a project featuring HTML, CSS, and Vanilla JavaScript

Our task was to create a project that exclusively utilized JSON files for data storage. The data structure we were working with resembles the following: [ { "aircraftName": "Boeing 747", "departDate": 1640173020000, ...

Steps to eliminate a horizontal scrollbar

It appears that I am working with CSS 2.1 as the style "overflow-x" is not present in my code. In the snippet below, I have defined headings for a grid and set the Id "pageLength" to introduce a vertical scrollbar for the grid's contents. However, thi ...

Using a global CSS file in Angular can lead to large module bundles being emitted by Webpack

In our Angular application generated with angular-cli, we are utilizing various global styles and imports defined in the styles.scss file (which begins with /* You can add global styles to this file, and also import other style files */ if that sounds fami ...

Create a customized HTML popup featuring various packages

I am struggling to create an HTML popup within a React component due to some errors Here is the code snippet: <div> <button class="toggle">Button</button> <div id="link-box"> <ul> ...

Background color and page height

When attempting to place a background image on the body element and the page height exceeds that of the viewport, allowing for vertical scrolling. In this case, the background image seems to start or end at the point where the viewport ends when scrollTop ...

Tips for maintaining the navigation tab's consistent appearance

Whenever I click a button on the sidebar and the current tab is the second tab, the navigation bar switches to display the first tab. How can I prevent this switch and keep the second tab displayed when clicking a button on the sidebar? The code for this ...

The perplexing phenomena of Ajax jQuery errors

Hey there! I'm having a bit of trouble with ajax jquery and could use some guidance. $.ajax({ type:"get", url:"www.google.com", success: function(html) { alert("success"); }, error : function(request,status,error) { alert(st ...

ui-grid row size set to automatically adjust using rowHeight : 'auto'

Has anyone else experienced this strange behavior with ui-grid? When I set the rowHeight to auto, each cell in the same row ends up with different heights. One of the cells contains multiline data, which seems to be causing issues for ui-grid. I've ev ...

Struggling with setting margins effectively in Bootstrap for the desired layout

I am attempting to create two columns with space between them, but whenever I try to add a margin-right, one of the columns goes down. Can someone please assist me? <div class=row> <div class="boxi col-6"> Content here ...

Ways to move the scroll to the bottom of the div by clicking

Can anyone help with why my scroll code isn't working? I'm trying to make the scroll go to the bottom when I click on $('#openDiv'). For example, when you enter a chat room on stackoverflow, the scroll is automatically at the bottom, a ...

determining the user's position within the <s:select> element

I have a dropdown select tag in my code with a list of countries. I want the user's country to be auto-selected when they access the page. This is the JSP code snippet: <s:select name="dropdown" list="countries" listKey="value" listV ...

Is it possible to rearrange column order in Bootstrap 4x according to different viewport sizes?

One of the great things about Bootstrap is its ability to rearrange columns regardless of the HTML structure. However, I am looking to have a different order of elements when the viewport size is smaller (e.g., Mobile). The current HTML structure looks li ...

How can Angular CLI prevent the submission of an HTML form unless a previous option has been selected

I am currently working on a form that contains select fields with various options pre-populated. <form [formGroup]="selectVehicleForm"> <select formControlName="Manufacturer"> <option *ngFor='let ...

Is there a way to eliminate the hover effect on a button within a navbar?

I'm currently working on a website using Angular and I have implemented a gray navbar with a hamburger icon that reveals a dropdown menu upon clicking. One of the menu items is "Projects," which when hovered over, displays individual links to various ...

Siblings selectors within Internet Explorer slow down significantly when using the :hover pseudo-class

Sample page: http://jsfiddle.net/y2pwqch6/6/ This particular example showcases a CSS selector known as the adjacent sibling selector: .l:hover + .r { color: blue } The issue arises when hovering over any element on the page, causing Internet Explore ...

Is there a way to retrieve the hand-drawn lines at no cost in the form of a list, with each line represented as a collection of coordinates

I am currently contemplating the idea of utilizing fabric.js for an online handwriting recognition system. In order to make this system work, I need to transmit the sketched lines as a collection of lines, where each line consists of several points. If a ...