I am working with two tables - table1 contains only th
tags and table2 contains only td
tags. Despite the unconventional setup, it is due to limitations in the application. Each TH
in table1 acts as a sorting button corresponding to the TD
in table2.
While the full width of both tables is the same, the TH
's and TD
's have different widths causing misalignment. I need to find a solution to link each individual TH
to the width of the TD
below it. The challenge lies in the dynamic nature of the TH
sorting buttons, as users can add or remove them, requiring the widths to adjust accordingly. Finding a seamless linking mechanism is proving difficult. Any suggestions?
For example:
<table id="table1">
<thead>
<th>Sort 1</th>
<th>Sort 2</th>
<th>Sort 3</th>
<th>Sort 4</th>
</thead>
</table>
<table id="table2">
<thead>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</thead>
</table>
I have created a basic Fiddle illustrating the issue. The last few td
's get squeezed into the "Sorts7" column. My goal is for the TH
and corresponding TD
to maintain equal width, regardless of added or removed columns.
Thank you for your assistance.
Edit: It is necessary for the two tables to remain separate, despite the inconvenience.