In Part 1 of this series, we took a structured approach and used easy, reusable code blocks to create a responsive HTML newsletter with a mix of one-, two- and three-column content areas. In this issue, we'll tackle another layout variant – a two-column design with a small sidebar and a larger area for the main content.

Sidebar Layout

A sidebar layout can be very useful because it allows you to neatly organize your newsletter into a larger area with the most important content and a smaller area with less important or tangential content. On larger screens like a desktop monitor or a tablet, this works beautifully. However, on smaller mobile screens, there isn't enough room to display the sidebar and the main content area side-by-side, so you need to code the layout in a way that the columns become stacked, one above the other, similar to the two- and three-column content blocks that we used in the previous issue.

In fact, a sidebar layout is essentially a two-column design. The only difference is that instead of splitting the two columns 50%-50%, we would split them, for example, 33%-66% so that the sidebar occupies a third of the newsletter width, while the main content area occupies two thirds of the width. To accomplish this, we could simply take the two-column block that we used before and change the widths of the two columns as shown below:

However, this could be problematic depending on what type of content we have in the sidebar. The two-column content block as coded above will always place the left column (in this case the sidebar) above the right column with the main content once the viewport falls below the full width of the newsletter and the media query kicks in. This may be fine if your sidebar contains some type of introduction or a table of contents, which would need to come first. However, what if the sidebar contains less important content or things like subscription and contact details? It wouldn't make sense for this column to be stacked above the more important content, so we need to take a different approach to our two columns.

Columns as Cells vs Tables

In the above approach, the two columns are created by two cells inside the same table. The media query that handles what happens on smaller screens simply gives each cell a width of 100% and displays them as block-level elements rather than table cells once the viewport falls below the width of the newsletter. This is what triggers the stacking effect.

Whatever column appears first in the HTML code will always be stacked on top on smaller screens. So if we want the main content area to be stacked above the sidebar, we need to modify our layout in a way that puts the code for the main content area before the code for the sidebar, yet displaying the main content area on the right side on larger screens. Luckily, we can accomplish this by creating the two columns with two separate tables instead of cells inside the same table.

As you can see, the HTML code is actually quite straightforward. We place two separate tables inside the top-level table. We give the table containing the main content area a width of 66% and right-align it. We then give the table containing the sidebar a width of 33% and left-align it. We assign both tables a class of "table", which we add to the media query.

The end result is that our sidebar is displayed on the left, and the main content area is displayed on the right on larger screens. And because the main content area comes before the sidebar in the code, once the stacking occurs on smaller screens, the main content area is stacked on top, which is the outcome that we want.

One thing to keep in mind is that when aligning tables like this, Outlook has a tendency to add extra spacing around each table, so it's important to leave a little margin. That's why we use 33% and 66% for our two columns rather than 33% and 67%. The same goes for images, if you hard-code a width for your images inside the two columns, take a few pixels off on both sides to ensure that Outlook doesn't break your layout. Since we code our images with a width of 100% (which Outlook doesn't support) as well as a hard-coded pixel width, the images will be displayed at 100% of each column in all other email clients, while Outlook will use the hard-coded pixel width, which is just a few pixels smaller to accommodate its quirks.

Example

Let's continue with the same example as last time – in other words, a monthly newsletter for an imaginary airline containing the latest travel deals. We will use exactly the same content, except that we'll reorganize it into our new sidebar layout.

As you can see, we simply copied and pasted the one- and two-column pieces from the previous newsletter inside the 66% table and the three-column pieces inside the 33% sidebar table. The end result is that on a larger screen, the minor flight deals are contained in the sidebar, together with contact and subscription details, while the more important feature articles are in the main content area. As the viewport falls below 650px, the layout becomes a simple one-column design, with the main feature articles stacked on top, while the minor flight deals as well as the contact and unsubscribe information falls below.

If we wanted the sidebar on the right side instead of the left, we wouldn't flip-flop the two tables in the code because whatever column you want stacked above still needs to come first in the HTML. Instead, we would simply change align="right" and padding-left: 10px to align="left" and padding-right: 10px for the main content area and vice-versa for the sidebar.

Remember to resize your browser window to see how the two columns are rearranged as you go to a smaller viewport and below the 650px breakpoint.

All Components

To view all of the different types of content blocks that we have used in these two tutorials, see the list below. You can use any of these components to create your own HTML newsletter templates in LISTSERV. Simply make any color and style adjustments as needed and replace the sample headline, text, images and links with placeholders like &*HEADLINE;, &*TEXT;, &*IMAGE;, &*LINKTEXT; and &*URL;, and you'll be able to send your own responsive HTML newsletters in no time.