Making HTML table responsive friendly

Hello,

How do I easily make a table like this that looks good on mobile. I don't need to stay with a standard html table

http://vnkkh.ervny.servertrust.com/pricing-s/116.htm
LVL 7
weikelbobAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle HamiltonData ScientistCommented:
You should transpose the data so that you have less columns, more rows:

     Number of Scans   |      Price   |    dpi    
_____________________________________________
A       500             |    $53.50  |  600dpi
_____________________________________________
B       500             |    $53.50  |  600dpi
_____________________________________________
C       500             |    $53.50  |  600dpi
_____________________________________________
D       500             |    $53.50  |  600dpi
_____________________________________________
E       500             |    $53.50  |  600dpi
_____________________________________________
F       500             |    $53.50  |  600dpi
_____________________________________________

Open in new window


there are numerous ways of doing that. You can keep your html table and show a transposed (via javascript) version for mobile. I do it using modular arithmetic, but there are also a bunch of code examples out there that do other tricks

Here's one that uses only CSS:
https://css-tricks.com/examples/ResponsiveTables/responsive.php

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
It would help if you can create an image of what you want the table to look like.  Use powerpoint or google apps presentation if you need to just make some shapes and text to get a feel for what the mobile version looks like.  From there you can use media queries to rearrange things at different viewports.  When you have a table with a lot of columns it is harder because you have to play with the visuals to get the information in a form you are happy with.  Sometimes I will just remove or hide columns on mobile viewports depending on what it is.
weikelbobAuthor Commented:
Is there a way to show one table for mobile and one table for desktop? Different code.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Kyle HamiltonData ScientistCommented:
yes, absolutely. use media queries to show/hide elements
Jessica WhitleySoftware DeveloperCommented:
This is a great example of responsive data tables.  It doesn't take much to use 1 table and have it adjust to screen size based on the device being used at the time.

https://css-tricks.com/responsive-data-tables/
Kyle HamiltonData ScientistCommented:
@Jessica, as much respect as I have for Chris Coyer, that's actually a really bad example because he puts content in the CSS. It's not bad just rhetorically. If your data is dynamic, then your CSS file will also have to be dynamic. You can come up with "fixes", but essentially, you've created yourself and your team a nice little headache.
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Instead of using a table, you can easily do this using bootstrap responsive css.  http://getbootstrap.com/  

Working Sample https://jsbin.com/yadoni/edit?output
<!DOCTYPE html>
<html>
<head>
  <style>
    .row{
      border-bottom:solid thin;
      margin-bottom:10px;
      padding-bottom:5px;
    }
  </style>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<div class="row">
  <div class="col-sm-2 col-xs-4">1</div>
  <div class="col-sm-1 col-xs-4">2</div>  
  <div class="col-sm-3 col-xs-4">3</div>  
  <div class="col-sm-1 col-xs-4">4</div>  
  <div class="col-sm-1 col-xs-4">5</div>  
  <div class="col-sm-1 col-xs-4">6</div>  
  <div class="col-sm-1 col-xs-4">7</div>  
  <div class="col-sm-1 col-xs-4">8</div>  
   
</div>
<div class="row">
  <div class="col-sm-2 col-xs-4">1</div>
  <div class="col-sm-1 col-xs-4">2</div>  
  <div class="col-sm-3 col-xs-4">3</div>  
  <div class="col-sm-1 col-xs-4">4</div>  
  <div class="col-sm-1 col-xs-4">5</div>  
  <div class="col-sm-1 col-xs-4">6</div>  
  <div class="col-sm-1 col-xs-4">7</div>  
  <div class="col-sm-1 col-xs-4">8</div>  
   
</div>
  <div class="row">
  <div class="col-sm-2 col-xs-4">1</div>
  <div class="col-sm-1 col-xs-4">2</div>  
  <div class="col-sm-3 col-xs-4">3</div>  
  <div class="col-sm-1 col-xs-4">4</div>  
  <div class="col-sm-1 col-xs-4">5</div>  
  <div class="col-sm-1 col-xs-4">6</div>  
  <div class="col-sm-1 col-xs-4">7</div>  
  <div class="col-sm-1 col-xs-4">8</div>  
   
</div> 
  <div class="row">
  <div class="col-sm-2 col-xs-4">1</div>
  <div class="col-sm-1 col-xs-4">2</div>  
  <div class="col-sm-3 col-xs-4">3</div>  
  <div class="col-sm-1 col-xs-4">4</div>  
  <div class="col-sm-1 col-xs-4">5</div>  
  <div class="col-sm-1 col-xs-4">6</div>  
  <div class="col-sm-1 col-xs-4">7</div>  
  <div class="col-sm-1 col-xs-4">8</div>  
   
</div> 
  <div class="row">
  <div class="col-sm-2 col-xs-4">1</div>
  <div class="col-sm-1 col-xs-4">2</div>  
  <div class="col-sm-3 col-xs-4">3</div>  
  <div class="col-sm-1 col-xs-4">4</div>  
  <div class="col-sm-1 col-xs-4">5</div>  
  <div class="col-sm-1 col-xs-4">6</div>  
  <div class="col-sm-1 col-xs-4">7</div>  
  <div class="col-sm-1 col-xs-4">8</div>  
   
</div> 
</body>
</html>

Open in new window

For just this part, you don't need to include the query portion, just the css.  Bootstrap is build on a 12 column responsive grid.  Each class of "row" would equate to a table <tr> and the interior div's would be the <td>.  You will see I have 2 classes on the interior div's that look like, "col-sm-1 col-xs-4".  This hits the built in media queries and makes the columns on a small screen or larger the width equivalent to 1/12 (one of twelve columns) the parent and on an extra small screen, 4/12 (1 of 3 columns) the parent container.  

On my sample link as you narrow the browser you will see the 12 columns collapse to 2 rows of 3 columns.  The grid for bootstrap is explained in more detail http://getbootstrap.com/css/#grid. If you want to stick with a traditional table, there are utilities in bootstrap you can use to show or hide columns based on the screen resolution http://getbootstrap.com/css/#responsive-utilities

If you are trying to show a table with a lot of data, this may be easier to use.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.