It appears that the question is quite broad as it lacks clarity regarding the type of markup being used and the definitive rules assumed.
If you are dealing with an HTML table featuring alternate sequences of images and texts, such as "row of images, row of texts, row of images, row of texts," there seems to be a content issue at hand.
The tabular markup has been utilized to represent non-tabular data, resulting in the splitting of data to cater to visual aesthetics rather than logical structure.
While you mentioned a reluctance to alter the table markup, some changes will likely be necessary. In this case, I recommend following the HTML5 approach, which involves utilizing the <figure>
and <figcaption>
elements.
To streamline the process, consider automating the following modifications to the source code using JavaScript:
- Enclose all images within a
<figure>
element
- Move all text content into the corresponding
<figure>
element and wrap them in a <figcaption>
tag.
- Delete the rows containing text content.
Subsequently, apply display: inline-block;
to the td
elements for achieving the desired outcome.
Check out the demo by running it on a full page and resizing the window to witness the <td>
elements becoming flexible.
figure {
margin: 0;
text-align: center;
}
td {
vertical-align: top;
display: inline-block;
}
<table>
<tr>
<td>
<figure>
<img src="https://i.sstatic.net/C1285.jpg" alt="Dog">
<figcaption>“A dog is the only thing on earth that loves <br>you
more than he loves himself.”
<br>
<a href="http://www.goodreads.com/author/show/1865038.Josh_Billings">
Josh Billings</a>
</figcaption>
</figure>
</td>
<td>
<figure>
<img src="https://i.sstatic.net/FW9qs.jpg" alt="Cat">
<figcaption>“What greater gift than the love of a cat.”
<br>
<a href="http://www.goodreads.com/author/show/239579.Charles_Dickens">
Charles Dickens</a>
</figcaption>
</figure>
</td>
</tr>
</table>
Although it might not provide a straightforward solution, given the unique nature of your issue, it's unlikely to find one here (assuming it exists).