Tips for creating responsive emails

Yesterday, I posted about my email newsletter and received some helpful feedback on creating a good structure. I implemented the suggestions provided into my newsletter and also added media query code to make layout adjustments for supported email clients. However, I encountered an issue as the media queries did not work as expected in my email newsletter. If you would like to see the visual representation of the desktop version email, and the mobile version email. The main difference between the two versions is visible in the four columns section.

  1. In the mobile version, there should be two columns instead of four.
  2. The last two columns need to be positioned below the first two columns with spacing from the top to ensure that the vertical borders do not touch.
  3. For desktop view, every column should have a right border except for the last one. In the mobile view, the second and fourth columns should not have a right border.

To achieve these layout changes, I structured my code in the following way:

  1. There are four columns below the logo, organized as two separate tables with two columns each. The parent table's width is set at 640 pixels, while the child tables' width is set at 320 pixels. The first child table aligns to the left so they are displayed side by side. To ensure proper display in mobile view, I adjusted the main table's width to 320 pixels so the child tables stack vertically.
  2. I added padding-top: 20px to the second child table in the mobile view to create space between it and the table above.
  3. For columns without a right-border property in the mobile view, I applied a specific class and set border: 0; for those columns.

In the head code:

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0" />
<title>Email</title>
<style>
@media only screen and (max-device-width: 480px) { 
    table[class="mainTable"] {
        width: 320px !important;
    }
    table[class="subTable"] {
        padding: 20px 0 0 !important;   
    }
    td[class="noBorder"] {
        border: 0 !important;
    }
}
</style>

In the body code:

<table width="640" border="0" cellspacing="0" cellpadding="0" class="mainTable" style="margin: 0px auto; font-family: Helvetica, Arial, sans-serif; padding: 35px 0 0;">
        <tr>
            <td style="font-size: 25px;">
                LOGO
            </td>
        </tr>
        <tr>
            <td>
                <table align="left" width="320" border="0" cellspacing="0" cellpadding="0" style="margin: 0; padding: 0;">
                    <tr>
                        <td align="center" valign="top" style="padding: 15px 0 15px; width: 160px; height: 150px; border-right: 1px solid #666;">
                            <p style="margin: 0; padding: 5px 0 10px;">Remaining</p>
                            <p style="font-size: 35px; margin: 0 0 20px;">12d, 17hr</p>
                            <a style="background: #ccc; color: #000; font-weight: bold; text-decoration: none; padding: 5px 10px;" href="#">Visit</a>
                        </td>
                        <td align="center" valign="top" class="noBorder" style="padding: 15px 0 15px; width: 160px; height: 150px; border-right: 1px solid #666;">
                            <p style="margin: 0; padding: 5px 0 10px;">Remaining</p>
                            <p style="font-size: 35px; margin: 0 0 20px;">12d, 17hr</p>
                            <a style="background: #ccc; color: #000; font-weight: bold; text-decoration: none; padding: 5px 10px;" href="#">Visit</a>
                        </td>
                    </tr>
                </table>
                <table width="320" border="0" cellspacing="0" cellpadding="0" class="subTable" style="margin: 0; padding: 0;">
                    <tr>
                        <td align="center" valign="top" style="padding: 15px 0 15px; width: 160px; height: 150px; border-right: 1px solid #666;">
                            <p style="margin: 0; padding: 5px 0 10px;">Remaining</p>
                            <p style="font-size: 35px; margin: 0 0 20px;">12d, 17hr</p>
                            <a style="background: #ccc; color: #000; font-weight: bold; text-decoration: none; padding: 5px 10px;" href="#">Visit</a>
                        </td>
                        <td align="center" valign="top" style="padding: 15px 0 15px; width: 160px; height: 150px;">
                            <p style="margin: 0; padding: 5px 0 10px;">Remaining</p>
                            <p style="font-size: 35px; margin: 0 0 20px;">12d, 17hr</p>
                            <a style="background: #ccc; color: #000; font-weight: bold; text-decoration: none; padding: 5px 10px;" href="#">Visit</a>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
            </td>
        </tr>
        <tr>
            <td>
                <ul>
                    <li>Item 1</li>
                    <li>Item 2</li>
                    <li>Item 3</li>
                    <li>Item 4</li>
                </ul>
            </td>
        </tr>
        <tr>
            <td>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
            </td>
        </tr>
    </table>

Despite these efforts, the changes did not reflect correctly in the mobile view. Upon testing in the Android Gmail app, which may not fully support media query, and the Sony android default Email app which should support it, no significant change was observed. This lack of responsiveness warrants further investigation and testing across different devices. Unfortunately, I currently do not have access to other mobile devices for testing purposes.

Answer №1

Creating a responsive email can feel like a futile task, given the number of email clients that may not display your design as intended.

When it comes to HTML emails, it's best to stick to the basics - tables, images, and inline styles like it's 1999.

If you really need it to be responsive, consider removing table widths and letting them adapt naturally.

For more tips on coding HTML emails, check out this resource:

Answer №2

Yesterday, I shared a response (the duplicate that was later deleted) where I believe I provided a link to this basic responsive example.

I noticed that you have not implemented the display:block; toggle. Your email section should be structured like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title></title>
  <style type="text/css">
    @media only screen and (max-width: 600px) { .switch { width:100%; display:block; } }
  </style>
</head>
<body>

<table width="600" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="50%" class="switch">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="50%" valign="top" style="padding:30px;" bgcolor="#333333">
            Cell 1
          </td>
          <td width="50%" valign="top" style="padding:30px;" bgcolor="#444444">
            Cell 2
          </td>
        </tr>
      </table>
    </td>
    <td width="50%" class="switch">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="50%" valign="top" style="padding:30px;" bgcolor="#555555">
            Cell 3
          </td>
          <td width="50%" valign="top" style="padding:30px;" bgcolor="#666666">
            Cell 4
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

</body></html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display outcome prior to completion of the website processing in http/html/ajax

I am currently exploring ways to display a wait message in a web application while a task is running for an extended period of time. I am struggling with whether it is even possible. The issue seems to be that the website will only return to the user&apos ...

Can someone show me how to verify in PHP (using codeigniter) if the following two rows contain any data?

I need to verify whether the following TWO rows or ID are not NULL. If there are no consecutive TWO rows or ID, then the income will stay at zero. foreach ($data as $row) { if(($row->id + 2) != NULL) //I am unsure about the c ...

Creating and adding nested div elements with the power of JavaScript

My goal is to utilize JavaScript for updating the CSS layout as the webpage loads. Below is the code I have been working on: var container = 0; // Total UI Container var containerTitle = 0; // Title Container var article = 0; var articleTitle = 0; var ...

Having trouble identifying the specific CSS property that is being used or inherited

I have incorporated components from Twitter Bootstrap CSS into a custom CSS file, focusing mainly on toolbar components. Specifically, I have set up a toolbar with various features. However, when applying additional CSS to the .signinbox_left:hover select ...

How can I restrict the number of characters per line in a textarea using javascript or jQuery?

Is there a method to control the number of characters per line in a textarea? For example, on lines 1-3 of the textarea, only 20 characters can be entered, while on subsequent lines, up to 50 characters are allowed. The current structure of the textarea l ...

How can the default text color be adjusted in NSAttributedString when initialized with HTML dark mode?

During the process of converting my existing app to dark mode, I came across an instance where I needed to initialize a UITextView with an NSAttributedString for displaying some legal text from the app store. While everything looked good in light mode, swi ...

Ways to retrieve various data elements from ajax using PHP

Can you help me with my AJAX code that retrieves data from a PHP script? I want to know how to set multiple echo variables in PHP and display them separately using AJAX without reloading the page. AJAX Code $(document).ready(function() { //el ...

Elements within the Div are perfectly aligned in the center and restricted from moving to either the left or right edges of the

Currently, I am developing a project similar to Gmail. In order to achieve this, I need to design a div container that consists of various components such as Inbox, Send, Draft, etc. However, when I attempt to move these components around, the icons disapp ...

Add two columns for mobile devices in the Woocommerce platform

How can I display 2 columns of products in my Woocommerce shop using a child theme based on 'Shopisle'? Is a CSS-only solution the best approach for this task, and will it work smoothly without any bugs? I suspect that the theme is built on Boot ...

Align the radio button group in the center with corresponding labels

I have several radio buttons with labels that vary in length. I am trying to figure out how to center them horizontally so that the labels are centered on the page, but still appear as if they are left-aligned. Desired result: Current HTML snippet: < ...

What is the best approach for resolving the issue of User having an Unknown field(s) (Id_card_number) specified in the system

I'm facing an issue with my code. Whenever I run a makemigrations command, it returns an error message saying Unknown field(s) (Id_card_number) specified for User. How can I resolve this problem? settings.py INSTALLED_APPS = [ 'django.contr ...

Techniques for preventing background layering using CSS

I have implemented a background image on the <input type="submit"> element to give it the appearance of a button. My CSS code looks like this: input.button { background-image:url(/path/to/image.png); } Furthermore, I would like to display a dif ...

What are some strategies for customizing the appearance of child components within a parent component?

I have a scenario where I am using parent and child components. When I use the HTML in another component, I also apply my CSS. For example, in my parent component: HTML <div class="chips"> <p class="tags">Tag 1</p&g ...

Page refresh enhances hover effect style

Is there a way to maintain a "hover" style even after a page refresh if the user does not move their mouse? The hover effect is only activated on mouse enter/mouseover events, so when the page refreshes, the style doesn't persist unless the user inter ...

What is the best way to ensure that two divs have aligned bottom edges?

I have a set of div containers positioned in different columns within a grid layout. I am looking for a way to identify the containers where the bottom edge is less than 50px higher than any other container, and adjust their heights so they align perfectly ...

How can I make a div's height match that of another div?

I am curious about adjusting the height of a div based on its content. In this case, I have the following HTML structure: div.Pantalla { background-image: url("https://cdn.pixabay.com/photo/2015/07/11/23/02/plane-841441_1280.jpg"); background-size ...

Sneaky spam and ads embedded within Joomla template

Today, while examining the source code of a Joomla site I am developing, I stumbled upon some hidden links that seem to be spam. I have spent an hour searching through various template files but have been unable to locate them. The hidden links in questio ...

What is the best method for showing information beneath each tab?

Here is my CodePen link: https://codepen.io/santoshch/pen/MWpYdXK .tab1border{ border-right: 2px solid #f0f0f0; } .tab2border{ border-right: 2px solid #f0f0f0; } .tab3border{ border-right: 2px solid #f0f0f0; } .tab4border{ border-right: 2px soli ...

Integrating HTML, JavaScript, PHP, and MySQL to enhance website functionality

Exploring the intricacies of HTML, JavaScript, PHP, and MySQL, I have been working on an order form to understand their interactions. View Order Form The aim of this table is to allow users to input a quantity for a product and have JavaScript automatica ...

Interior CSS border

Check out my progress so far: jsfiddle.net/warpoluido/JkDhN/175/ I'm attempting to adjust the height of the green section to be slightly higher than the blue (or similar color) one, as shown in the image. The design needs to remain responsive. < ...