css - Reducing colspan on table cells when using @media queries to hide unneeded columns in mobile -
i'm trying find way, using css, change colspan on base of responsive table such found on shopping cart. happens is, @ lower resolutions, columns trimmed off preserve horizontal space. leaves col spanned rows "hanging" on end, preserving original width, causing overflow situations. know, horizontal overflows on mobiles pain.
so there way, using css, change colspan of table rows? i know how js, using listener frame, i'm curious if there kinda css hack instead. prevent bit of fouc.
here fiddle example: https://jsfiddle.net/dhaupin/5pv5qmru/3/
here example table structure:
<table> <thead> <tr> <td class="image">image</td> <td>name</td> <td>model</td> <td>qty</td> <td>price</td> </tr> </thead> <tbody> <tr> <td class="image">-- img --</td> <td>this red hat</td> <td>hat-red-2384</td> <td>2</td> <td>$13.22</td> </tr> <tr> <td class="total right" colspan="4">subtotal:</td> <td>$26.44</td> </tr> <tr> <td class="total right" colspan="4">shipping:</td> <td>$6.65</td> </tr> <tr> <td class="total right" colspan="4">total:</td> <td>$33.10</td> </tr> </tbody> </table> and default css, hiding "image" column @ 640px or less:
table { border-collapse: collapse; } td { border: 1px solid grey; padding: 4px; width: 18%; } .right { text-align: right; } @media (max-width: 640px) { td.image { display: none; /* kinda css hack here "hide" without "hiding? */ } td.total { /* colspan 3 here? how make span cleanly? */ } } here full width looks like:
here looks on smaller res, notice overflow of colspan on bottom:
i know not best solution css not allow change native html table attribute value.
more information can fount here: html colspan in css
for better solution can use js/ jquery , change attribute colspan td.total
@media (max-width: 480px) { td.image { position: absolute; left: -99999px; } } 

Comments
Post a Comment