Create an interactive table in your WordPress website that adjusts to different screen sizes

Having scoured numerous posts on responsive tables in this stack, I am still unable to find a solution to my specific issue. It's quite possible that I didn't know what exactly to look for, hence my resorting to posting a question here.

The crux of the matter is simple: I'm constructing a WordPress site and decided to create my own pricing table as I wasn't satisfied with the theme's version. You can view the table on my Wordpress page by following this link:

While the table itself looks good, I'm struggling with making it responsive. Below is the HTML I've inserted into the raw HTML widget of Visual Composer within WordPress:

<style type="text/css">    
/*General styles*/

/*Features table------------------------------------------------------------*/
@media screen and (max-width: 640px) {
    .features-table {
        overflow-x: auto;
        display: block;
    }
}
.features-table {
font-family:'Open Sans';

margin: 0 auto;
border-collapse: separate;
border-spacing: 0;
text-shadow: 0 1px 0 #fff;
color: #2a2a2a;
background: #fafafa;  
background-image: -moz-linear-gradient(top, #fff, #eaeaea, #fff); /* Firefox 3.6 */
background-image: -webkit-gradient(linear,center bottom,center top,from(#fff),color-stop(0.5, #eaeaea),to(#fff)); 
}

#check {
color: #26CCA4;
font-size:20px;
}
#cross {
color: #E74A4A;
font-size: 20px;
}
...
...
/*Remaining code removed for brevity*/


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

You can access the JSfiddle with my complete code here: https://jsfiddle.net/d96q4h3d/

I have managed to make my table draggable along the x-axis using a media query and setting overflow-x to auto. However, I wish for the table to display in its entirety upon page load so users can view the full content at once, enabling them to zoom in on specific sections if needed.

Any assistance regarding this dilemma would be greatly appreciated. Despite extensive Google searches, I haven't come across a definitive solution explaining how to showcase the complete table on the page initially.

Thank you!

Answer №1

To start, remove the CSS property white-space: nowrap;

Next, define the maximum width of the table to your desired size

For example, set the max-width to 900px as shown in this demo: https://jsfiddle.net/d96q4h3d/7/

If you wish to make the table smaller, adjust the size of the <thead> elements and the "#price" id like so:

@media screen and (max-width: 800px) {
    .features-table thead p {
    font-size: 20px !important;
    }
    #price {
    font-size: 20px;
    }
}

@media screen and (max-width: 600px) {
    .features-table thead p {
    font-size: 15px !important;
    }
    #price {
    font-size: 15px;
    }
    .features-table td{
    padding: 0px 10px;
    }
}

Remember to place your @media screen queries at the end of your stylesheet for proper styling!

Answer №2

Have you thought about utilizing a WordPress theme that is built with the Bootstrap framework?

By using this approach, you can implement this kind of structure to display your table, making it responsive without any difficulties.

<div class="table-responsive">
  <table class="table">
     insert your table data here
  </table>
</div>

Bootstrap provides an effective solution for creating responsive tables and various user interface components; its developers have put in significant effort to ensure compatibility across different browsers.

Answer №3

Finding a solution for responsive tables can be challenging due to their inherent design limitations. Fortunately, there are various techniques available to help achieve the desired outcome, with many involving the use of JavaScript.

If you're looking for a comprehensive collection of approaches, check out this resource which includes a particularly innovative pure CSS method (#8) that I personally favor:

EDIT:

In cases where it's essential for the entire table to be easily viewed on mobile devices, a potential solution could be to utilize this resource specifically:

https://github.com/ghepting/jquery-responsive-tables - DEMO

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

Preventing blank text entries in a task management application

Is there a way to determine if the text input provided by the user is empty or contains some text? I'm in the process of developing a TO-DO app and I'd like it so that if a user fails to enter anything into the text area and clicks on "add", the ...

Troubleshooting a malfunctioning PHP form that uses jQuery and AJAX

Snippet of HTML code: <form class="contact_form" action="" name="contact_form"> <ul><li> <input type="email" name="email" placeholder="Please enter your email here" required /> </li><li> <button class="submit" type=" ...

Is the table row changing in size when a filter script class is applied?

When trying to filter table rows by category and adding the class filterTr to the element <tr>, I noticed that the width of the <tr> element changes, causing it to no longer align with the <th> element above. I am unsure why this resizin ...

Dynamic font size that adjusts as you change the window dimensions

Is there a way to adjust the font size in HTML so that when I resize the window, the text size adjusts accordingly? It's like setting a percentage for the text based on the size of the container it is in. Let me provide an example of what I have in m ...

Is there a way to create a dropdown menu that transforms into a burger icon on smaller screens, while still housing all of my navigation items within it?

I'm currently working on a segment of my header that includes a navbar with 3 links, as well as a dropdown menu listing additional functionalities. Here is the current code I have: <div class="col-md-4 pt-4"> <nav class="navbar ...

Tips for adjusting the button spacing on a bootstrap navbar

As someone who doesn't work on front-end tasks frequently, I have encountered an issue while creating a navbar using Bootstrap. The problem arises when trying to add multiple buttons as it causes the spacing between them to appear strange. Does anyon ...

Creating a floating div that remains in place without disturbing the layout of the surrounding elements on

I am trying to place a div within a page at specific coordinates without affecting the rest of the content on the page. My initial approach was to give the parent container a position: absolute and the floating div a position: relative, then setting the p ...

Creating a dynamic canvas with a three-dimensional model using three.js: A step-by-step guide

I'm currently developing a website where I have integrated a canvas element to display a 3D object (specifically, a cube) using three.js. The canvas is housed within a div, following the guidelines found in various documentation. The issue arises wh ...

The HTML header is not displaying at the proper width as intended

Let me lay out the blueprint I had in mind for my webpage: The body will have a width and height of 600 x 800 pixels with no padding, allowing elements to snugly align without any margin. Inside the body, there will be 3 key elements - a header, main c ...

Several radial progress charts in JavaScript

While attempting to recreate and update this chart, I successfully created a separate chart but encountered difficulties with achieving the second progress. The secondary chart <div id="radial-progress-vha"> <div class="circle-vha ...

What is the reason for needing a page reload in Javascript or JQuery?

I'm curious why Javascript or jQuery require a page reload before applying certain effects. CSS updates in real-time, as demonstrated by the following example: This changes dynamically without needing to refresh the page @media all and (max-width:7 ...

Issue with displaying HTML escaped characters such as "&#39" results in showing a pound sign instead of a single quote

Whenever I store data in my Java code, I employ HtmlUtils.htmlEscape to ensure that HTML characters are escaped. However, when retrieving the data and trying to display it in an HTML format (using AngularJS 1.6), the escaped characters (&rsquo;, &am ...

Having trouble with jquery's empty() function not functioning as expected

I'm brand new to using jquery so I apologize in advance for any beginner mistakes. Essentially, my issue is straightforward: Here is the HTML code I have: <div class="v" align="center" id="div4"> <div id="div5" class="h blurb"> <sp ...

Guide on changing the CSS of MUI parent components to set the display of buttons to 'block' in React

I'm facing a challenge with my modal design for mobile view. I need the buttons to display in a stacked format, one above the other, taking up the full width of the modal. I've been exploring ways to override the existing CSS within the component ...

Adjust the dimensions of polymer components (checkbox)

When attempting to adjust the size of the paper-checkbox, I experimented with changing the width and height properties in my CSS file. Additionally, I tried using transform: scale(2,2). The scale property resulted in blurriness, while adjusting the width ...

Utilizing CSS to expand a section of an image from a sprite sheet across a div

I need to resize a div that is 1x5 and display an embedded image from a sprite sheet. I am looking for a CSS solution to either repeat or expand this div to cover the area of a larger div. Is there a way to achieve this using only CSS, or will it require ...

When I open my website in the browser, the bootstrap card-deck design is not being displayed correctly

I encountered a strange issue while designing my website. The code I wrote for the Bootstrap card-deck class in codeply.com was working perfectly fine. However, when I copied the same code into my PyCharm code editor and then pasted the file link into my b ...

Looking for assistance in reducing the vertical spacing between divs within a grid layout

Currently, I am in the process of developing a fluid grid section to showcase events. To ensure responsiveness on varying screen resolutions, I have incorporated media queries that adjust the size of the div elements accordingly. When all the divs are unif ...

What is the best way to identify the appropriate class name for searching in Selenium?

I'm currently on a mission to find an element based on its class name. I have extracted this snippet from the page source (which I saved as a file using BeautifulSoup): <div class="flex flex-column"><div... If I attempt to pinpoin ...

Frustrated with the endless page loading caused by three.js

I've been trying to incorporate three.js code to showcase a 3D model in GLTF format, but my webpage keeps getting stuck on pre-loading. I need assistance with displaying a preloading page until all the files are fully loaded. Any help in resolving th ...