Home > Software engineering >  Style HTML Table for Mobile
Style HTML Table for Mobile

Time:10-31

How do I better style my table for mobile? It looks fine on desktop but when I try to view the page on my phone all it shows is the middle of the table and I have to scroll left and right to view the other colums.

Here's the website - https://sites.google.com/view/cash-counts-arbys/home

Here's the code -

''' '''

<!DOCTYPE html>
<html>
<head>
  <style>
    body {
  background: #EEE;
  margin: 0;
  padding: 0;
}

/* Navigation */

.navigation {
  box-sizing: border-box;
  background-color: #3587A4;
  overflow: auto;
  padding: 18px 50px;
  position: relative;
  top: 0;
  width: 100%;
  z-index: 999;
}

ul {
  padding: 0;
  margin: 0;
}

li {
  color: #FFF;
  display: inline-block;
  font-family: 'Oxygen', sans-serif;
  font-size: 16px;
  font-weight: 300;
  letter-spacing: 2px;
  margin: 0;
  padding: 20px 18px 10px 18px;
  text-transform: uppercase;
}

.active {
  color: #88CCF1;
}

/* Table */

table {
  height: 40%;
  left: 10%;
  margin: 20px auto;
  overflow-y: scroll;
  position: static;
  width: 80%;
}

thead th {
  background: #88CCF1;
  color: #FFF;
  font-family: 'Lato', sans-serif;
  font-size: 16px;
  font-weight: 100;
  letter-spacing: 2px;
  text-transform: uppercase;
}

tr {
  background: #f4f7f8;
  border-bottom: 1px solid #FFF;
  margin-bottom: 5px;
}

th, td {
  font-family: 'Lato', sans-serif;
  font-weight: 400;
  padding: 20px;
  text-align: left;
  width: 33.3333%;
}

.search {
  background-color: #FFF;
  border: 1px solid #DDD;
  border-radius: 3px;
  color: #AAA;
  padding: 20px;
  margin: 50px auto 0px auto;
  width: 77%;
}
  </style>
  <title>Arbys Draw Counts</title>
  <link href="https://fonts.googleapis.com/css?family=Lato: 100,300,400,700|Luckiest Guy|Oxygen:300,400" rel="stylesheet">
  <link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>

  <ul >
    <li><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJUAAAB/CAMAAADRo3CZAAAAclBMVEX////XGSHVAADXFR7SAADsr6/XEhvWAA755ub  /vbR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>
  <table>
  <tr>
    <th>Bill Type</th>
    <th>Amount of Bills</th>
    <th>Cash Amount of Type</th>
  </tr>
  <tr>
    <td><label for="usd-100">100$</label></td>
    <td><input id="usd-100" type="number" step="1" min="0" value="0">$</td>
    <td><output for="usd-100">0</output>$</td>
  </tr>
  <tr>
    <td><label for="usd-50">50$</label></td>
    <td><input id="usd-50" type="number" step="1" min="0" value="0">$</td>
    <td><output for="usd-50">0</output>$</td>
  </tr>
  <tr>
    <td><label for="usd-20">20$</label></td>
    <td><input id="usd-20" type="number" step="1" min="0" value="0">$</td>
    <td><output for="usd-20">0</output>$</td>
  </tr>
  <tr>
    <td><label for="usd-10">10$</label></td>
    <td><input id="usd-10" type="number" step="1" min="0" value="0">$</td>
    <td><output for="usd-10">0</output>$</td>
  </tr>
  <tr>
    <td><label for="usd-5">5$</label></td>
    <td><input id="usd-5" type="number" step="1" min="0" value="0">$</td>
    <td><output for="usd-5">0</output>$</td>
  </tr>
  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
  
  </body>
  </html>
  <tr>
    <td><label for="usd-1">1$</label></td>
    <td><input id="usd-1" type="number" step="1" min="0" value="0">$</td>
    <td><output for="usd-1">0</output>$</td>
  </tr>
  <tr>
    <td colspan="2">Sum</td>
    <td><output for="usd-100 usd-50 usd-20 usd-10 usd-5 usd-1" id="sum-total">0</output>$</td>
  </tr>
</table>
<table>
  <tr>
    <th>Change Type</th>
    <th>Number of Coins</th>
    <th>Cash Amount of Type</th>
  </tr>
  <tr>
    <td><label for="usd-quarter">0.25$</label></td>
    <td><input id="usd-quarter" type="number" step="1" min="0" value="0"></td>
    <td><output for="usd-quarter">0</output>$</td>
  </tr>
  <tr>
    <td><label for="usd-dime">0.10$</label></td>
    <td><input id="usd-dime" type="number" step="1" min="0" value="0"></td>
    <td><output for="usd-dime">0</output>$</td>
  </tr>
  <tr>
    <td><label for="usd-nickel">0.05$</label></td>
    <td><input id="usd-nickel" type="number" step="1" min="0" value="0"></td>
    <td><output for="usd-nickel">0</output>$</td>
  </tr>
  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
  
  </body>
  </html>
  
  <tr>
    <td><label for="usd-penny">0.01$</label></td>
    <td><input id="usd-penny" type="number" step="1" min="0" value="0">$</td>
    <td><output for="usd-penny">0</output>$</td>
  </tr>
  <tr>
    <td colspan="2">Sum</td>
    <td><output for="usd-quarter usd-dime usd-nickel usd-penny" id="sum-total-change">0</output>$</td>
  </tr>
</table>
</body>
</html>

<html>
<body>
  <table>
    <tr>
      <th>Sum of Draw</th>
      <th>Drop</th>
      <th>Draw After Drop</th>
    </tr>
<!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
  
  </body>
  </html>
  
    <tr>
      <td><output id="draw">0</output>$</td>
      <td><input id="drop" type="number" step="1" min="0" value="0">$</td>
      <td><output id="newdraw">0</output>$</td>
    </tr>
  </table>
</body>
</html>
<script>
document.querySelectorAll('input').forEach(el =>
  el.addEventListener('change', function() {
    // getting the value of the inputs
    let usd_100     =  document.querySelector('#usd-100').value,
        usd_50      =  document.querySelector('#usd-50').value,
        usd_20      =  document.querySelector('#usd-20').value,
        usd_10      =  document.querySelector('#usd-10').value,
        usd_5       =  document.querySelector('#usd-5').value,
        usd_1       =  document.querySelector('#usd-1').value,
        usd_quarter =  document.querySelector('#usd-quarter').value,
        usd_dime    =  document.querySelector('#usd-dime').value,
        usd_nickel  =  document.querySelector('#usd-nickel').value,
        usd_penny   =  document.querySelector('#usd-penny').value,
        drop        =  document.querySelector('#drop').value;
    
    // calculating the sum of each row
    let sum_usd_100     = usd_100 * 100,
        sum_usd_50      = usd_50 * 50,
        sum_usd_20      = usd_20 * 20,
        sum_usd_10      = usd_10 * 10,
        sum_usd_5       = usd_5 * 5,
        sum_usd_1       = usd_1 * 1,
        sum_usd_quarter = usd_quarter / 4,
        sum_usd_dime    = usd_dime / 10,
        sum_usd_nickel  = usd_nickel / 20,
        sum_usd_penny   = usd_penny / 100,
        sum_drop        = drop * 1;
    
    // outputting the sum of each row
    document.querySelector('output[for="usd-100"]').value = sum_usd_100;
    document.querySelector('output[for="usd-50"]').value = sum_usd_50;
    document.querySelector('output[for="usd-20"]').value = sum_usd_20;
    document.querySelector('output[for="usd-10"]').value = sum_usd_10;
    document.querySelector('output[for="usd-5"]').value = sum_usd_5;
    document.querySelector('output[for="usd-1"]').value = sum_usd_1;
    document.querySelector('output[for="usd-quarter"]').value = sum_usd_quarter;
    document.querySelector('output[for="usd-dime"]').value = sum_usd_dime;
    document.querySelector('output[for="usd-nickel"]').value = sum_usd_nickel;
    document.querySelector('output[for="usd-penny"]').value = sum_usd_penny;
    
    // getting the total sum of the entire column
    document.querySelector('#sum-total').value = sum_usd_100   sum_usd_50   sum_usd_20   sum_usd_10   sum_usd_5   sum_usd_1;
    document.querySelector('#sum-total-change').value = sum_usd_quarter   sum_usd_dime   sum_usd_nickel   sum_usd_penny;
    document.querySelector('#draw').value = sum_usd_100   sum_usd_50   sum_usd_20   sum_usd_10   sum_usd_5   sum_usd_1   sum_usd_quarter   sum_usd_dime   sum_usd_nickel   sum_usd_penny;
    document.querySelector('#newdraw').value = sum_usd_100   sum_usd_50   sum_usd_20   sum_usd_10   sum_usd_5   sum_usd_1   sum_usd_quarter   sum_usd_dime   sum_usd_nickel   sum_usd_penny - sum_drop;
  })
)
</script>

''' '''

CodePudding user response:

Tables are inherently not very responsive for a few reasons, which is one of many reasons they aren't often used anymore. You're better off using a display: grid system.

The reason tables aren't responsive is because once content is entered into the cell, it is stuck in that cell, in that column, in that row until the end of time unless you want to get really complex with your styling.

Right now, your table has its own scroll on it, which is already going to act against you. In a small viewport, that scroll is going to make it more difficult for you to scroll on a touchscreen. In fact, most interaction is more difficult on a touchscreen, which is why Mobile First design is still used today, more than a decade after it was first conceived. Designing for the screen that has more requirements and fewer capabilities first is easier than trying to adapt an already-made large-screen design.

I have a few suggestions to start you off:

  1. Get rid of the inner scroll on your table
  2. Use display: grid; instead of a table
  3. Design your new grid-based form for mobile first, then adapt the mobile for desktop
  4. Use your phone to look at pages with similar content to get an idea about sizing for your margins, padding, height, font-size, etc.
  • Related