Reverse Stack
With responsive HTML emails, you sometimes need to reverse the order in which stacked columns appear on mobile. You might even want to set a custom stacking order for layouts with 3+ columns.
Reverse 2 col
Imagine a two column layout, with text on the left and an image on the right:
<table class="w-full">
<tr>
<th class="sm:block w-1/2 sm:w-full px-8 font-sans font-normal text-left">
<p class="text-2xl font-hairline text-black">Left text</p>
<p class="text-gray-700">Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore aspernatur.</p>
</th>
<th class="sm:block w-1/2 sm:w-full px-8 font-normal text-left">
<img src="https://picsum.photos/600/600" alt="Unsplash photo">
</th>
</tr>
</table>
Naturally, the image will show under the text when viewed on a mobile device.
However, using table responsive display utilities, we can reverse the columns:
<table class="w-full">
<tr>
<th class="w-1/2 sm:table-footer-group px-8 font-sans font-normal text-left">
<div class="sm:w-full sm:px-8">
<h2 class="text-2xl font-hairline text-black">Left text</h2>
<p class="text-gray-700 m-0">Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore aspernatur.</p>
</div>
</th>
<th class="w-1/2 sm:table-header-group px-8 font-normal text-left">
<div class="sm:w-full sm:px-8">
<img src="https://picsum.photos/600/600" alt="Unsplash photo">
</div>
</th>
</tr>
</table>
It's done in 2 simple steps:
- Use the responsive
table-{...}-group
utilities on each column, to reverse column order on small screens - Wrap the contents of each column in a
<div>
and use it to set padding for mobile. This is required because the CSS properties used to reverse the column order do not support padding
Reorder 3+ cols
In a similar fashion, we can reorder a 3+ column layout:
<table class="w-full">
<tr class="sm:w-full sm:table">
<th class="w-1/3 sm:table-footer-group">
<div class="sm:px-8">
<h2 class="text-xl font-hairline text-white">Last on mobile</h2>
</div>
</th>
<th class="w-1/3 sm:table-footer-group">
<div class="sm:px-8">
<h2 class="text-xl font-hairline text-white">Second on mobile</h2>
</div>
</th>
<th class="w-1/3 sm:table-caption sm:w-full">
<div class="sm:px-8">
<h2 class="text-xl font-hairline text-white">First on mobile</h2>
</div>
</th>
</tr>
</table>
Only a couple of extra steps:
- Make the
<tr>
full width on mobile, by addingsm-w-full
andsm-table
- Use
sm-table-caption
andsm-w-full
on the column that you want to display first on mobile