Ecommerce Shopify WordPress Discussion

How can I customize a table so that it stacks vertically on media/mobile screens?

This page: https://eldergod.ca/necronomicodex/ looks great on desktop, but I dislike the horizontal scroll that occurs on some of the longer entries on mobile (I've tried both safari and chrome on my mobile to check). I've added this CSS to stack all the table columns. Can I force the table(s) to display at full width of the media device without any horizontal scrolling? /* XL */ @media (min-width: 1200px) { table {width:100%;} thead {display: none;} tr:nth-of-type(2n) {background-color: inherit;} tr td:first-child {background: #070707; font-weight:bold;font-size:1.5em;} tbody td {display: block; text-align:center;} tbody td:before { content: attr(data-th); display: block; text-align:center;} } /* Large */ @media (min-width: 768px) and (max-width: 979px) { table {width:100%;} thead {display: none;} tr:nth-of-type(2n) {background-color: inherit;} tr td:first-child {background: #070707; font-weight:bold;font-size:1.5em;} tbody td {display: block; text-align:center;} tbody td:before { content: attr(data-th); display: block; text-align:center;} } /* Medium */ @media (max-width: 767px) { table {width:100%;} thead {display: none;} tr:nth-of-type(2n) {background-color: inherit;} tr td:first-child {background: #070707; font-weight:bold;font-size:1.5em;} tbody td {display: block; text-align:center;} tbody td:before { content: attr(data-th); display: block; text-align:center;} } /* Small */ @media (max-width: 480px) { table {width:100%;} thead {display: none;} tr:nth-of-type(2n) {background-color: inherit;} tr td:first-child {background: #070707; font-weight:bold;font-size:1.5em;} tbody td {display: block; text-align:center;} tbody td:before { content: attr(data-th); display: block; text-align:center;} }
from what I can understand you are trying to stack tables vertically for smaller screen sizes. I have achieved this using media-queries in CSS. Here is an example table { margin: 0; padding: 0; width: 100%; table-layout: fixed; } table caption { font-size: 1.5em; margin: .5em 0 .75em; } table tr { background-color: #f8f8f8; border: 1px solid #ddd; padding: .35em; } table th, table td { padding: .625em; text-align: center; } table th { font-size: .85em; letter-spacing: .1em; text-transform: uppercase; } @media screen and (max-width: 600px) { table { border: 0; } table caption { font-size: 1.3em; } table thead { border: none; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; } table tr { border-bottom: 3px solid #ddd; display: block; margin-bottom: .625em; } table td { border-bottom: 1px solid #ddd; display: block; font-size: .8em; text-align: right; } table td::before { content: attr(data-label); float: left; font-weight: bold; text-transform: uppercase; } table td:last-child { border-bottom: 0; } } <table> <caption>Table</caption> <thead> <tr> <th>Name</th> <th>Age</th> <th>ID</th> </tr> </thead> <tbody> <tr> <td data-label="Name">XYZ</td> <td data-label="Age">24</td> <td data-label="Id">1</td> </tr> <tr> <td data-label="Name">John</td> <td data-label="age">28</td> <td data-label="Id">2</td> </tr> <tr> <td data-label="Name">Alex</td> <td data-label="Age">24</td> <td data-label="Id">3</td> </tr> <tr> <td data-label="Name">Dave</td> <td data-label="age">20</td> <td data-label="Id">4</td> </tr> </tbody> </table> Run code snippetExpand snippet Hope this helps :)

February 26, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.