Copy link to clipboard
Copied
I found this amazing CSS code class for a responsive table. I love it. The problem is that the media query for the mobile screen overrides other table classes I created. I tried to name the table something else, to avoid the problem. I named it ".table-lead-sheets". The first section workd perfectly, there is no override. The second section with the media query overrides the other table classes. Please advise on any suggestions. I have the code below. It is a great asset, if I could only figure out that one bug.
Copy link to clipboard
Copied
You would need to insert the table class infront of the td, th, tr. That would then target ONLY the td, th and tr in a table with the class name .table-lead-sheets - see if that helps.
.table-lead-sheets tr:nth-of-type(odd) {
Copy link to clipboard
Copied
Thanks, that worked well. The answers I saw in stackoverflow were confiusing, and did not work. One issue with your solution was that the hidden headers were suddenly exposed. I was able to hide them by leaving one of the tr tags alone and not naming it. Strange. I hope that doesn't cause any future inheritance problems. The other table looked fine though. CSS is not always logical.
Copy link to clipboard
Copied
If you must use tables to present spreadsheets or charts, don't use absolute positioning hacks.
On the off chance you're using Bootstrap, use responsive & striped classes. No added CSS required.
<table class="table caption-top responsive-table table-striped">
<caption>Bootstrap Responsive Table (Striped)</caption>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
Optionally, you can change bg-colors with contextual classes.
https://getbootstrap.com/docs/5.0/content/tables/#responsive-tables
Copy link to clipboard
Copied
@Nancy OShea wrote:If you must use tables to present spreadsheets or charts, don't use absolute positioning hacks.
The OP is obviously using a solution which labels the information vertically on small screens, not just deploying a simple table. Whether or not the solution is a good one or not is debatable. I try and avoid using tables like the plague and if and when its a necessity I don't know if I would have the desire to jump through hoops to make them fully responsible, maybe, quite possibly yes if I was doing me job properly, its not something I need to consider these days.
Copy link to clipboard
Copied
Why is absoulte positioning bad?
Thanks for the bootstrap table code, it looks interesting. I have also been experimenting with bootstap 3 column grids.
Copy link to clipboard
Copied
Why is absoulte positioning bad?
By @default0vaokg78cv42
Its NOT in the context that you are using it. A lot of responsive table solutions make use of absolute positioning to good effect.
Copy link to clipboard
Copied
Thanks, Nancy, for the bootstrap table code, it looks interesting. I have also been experimenting with bootstap 3 column grids.
Likes