I'm trying to find a way, using CSS, to change the colspan on the base of a responsive table such as that found on a shopping cart. So what happens is, at lower resolutions, certain columns are trimmed off to preserve horizontal space. This leaves the col spanned rows "hanging" over the end, essentially preserving the original width, causing overflow situations. As we know, horizontal overflows on mobiles is a pain.
So is there a way, using CSS, to change the colspan of table rows? I already know how to do this with JS, using a listener frame, but I'm curious if there was some kinda CSS hack I could do instead. This would help to prevent a bit of FOUC.
Here is a fiddle example: https://jsfiddle.net/Dhaupin/5pv5qmru/3/
Here is the 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 some default CSS, hiding the "image" column at 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;
/* some kinda css hack here to "hide" without "hiding? */
}
td.total {
/* colspan 3 here? how do we make it span cleanly? */
}
}
Here is what full width looks like:
Here is what it looks like on smaller res, notice the overflow of colspan on bottom: