Reconfiguring the order of rows in a responsive email table设计邮件。

Developing a newsletter layout can be challenging, especially when trying to incorporate responsiveness based on Mailchimp guidelines. One common issue that arises is the desire to have the second image appear before the corresponding text, particularly in single-column layouts.

For example: https://codepen.io/SergiOca/pen/vmqMoZ?editors=1010

 @media only screen and (max-width: 480px){
        #templateColumns{
            width:100% !important;
        }
    .templateColumnContainer{
        display:block !important;
        width:100% !important;
    }

    .columnImage{
        height:auto !important;
        max-width:480px !important;
        width:100% !important;
    }

    .leftColumnContent{
        font-size:16px !important;
        line-height:125% !important;
    }

    .rightColumnContent{
        font-size:16px !important;
        line-height:125% !important;
    }
}

<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateColumns">
    <tr>
        <td align="center" valign="top" width="50%" class="templateColumnContainer">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tr>
                    <td class="leftColumnContent">

                     <img src="http://placekitten.com/g/480/300" width="280" style="max-width:280px;" class="columnImage" />

                    </td>
                </tr>

            </table>
        </td>
        <td align="center" valign="top" width="50%" class="templateColumnContainer">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tr>
                    <td class="rightColumnContent">
                         <p style ="font-size:21px; color:#009DE0; width: 125px; line-height: 22px;";> Professional Selection for Staff or Freelance.</p>
                <p style="font-size: 13px; line-height: 19px; width: 218px;"> Based on a previously agreed Job description with the client, we proceed to interview and technically validate candidates who meet the established technical and personal requirements.</p>
                    </td>
                </tr>

            </table>
        </td>
    </tr>
</table>



<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateColumns">
    <tr>
        <td align="center" valign="top" width="50%" class="templateColumnContainer">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tr>
                    <td class="leftColumnContent">

                      <p style ="font-size:21px; color:#009DE0; width: 125px; line-height: 22px;";> Professional Selection for Staff or Freelance.</p>
                <p style="font-size: 13px; line-height: 19px; width: 218px;"> Based on a previously agreed Job description with the client, we proceed to interview and technically validate candidates who meet the established technical and personal requirements.</p>

                    </td>
                </tr>

            </table>
        </td>
        <td align="center" valign="top" width="50%" class="templateColumnContainer">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tr>
                    <td class="rightColumnContent">

                    <img src="http://placekitten.com/g/480/300" width="280" style="max-width:280px;" class="columnImage" />

                    </td>
                </tr>

            </table>
        </td>
    </tr>
</table>


<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateColumns">
    <tr>
        <td align="center" valign="top" width="50%" class="templateColumnContainer">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tr>
                    <td class="leftColumnContent">

                     <img src="http://placekitten.com/g/480/300" width="280" style="max-width:280px;" class="columnImage" />

                    </td>
                </tr>

            </table>
        </td>
        <td align="center" valign="top" width="50%" class="templateColumnContainer">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tr>
                    <td class="rightColumnContent">
                         <p style ="font-size:21px; color:#009DE0; width: 125px; line-height: 22px;";> Professional Selection for Staff or Freelance.</p>
                <p style="font-size: 13px; line-height: 19px; width: 218px;"> Based on a previously agreed Job description with the client, we proceed to interview and technically validate candidates who meet the established technical and personal requirements.</p>
                    </td>
                </tr>

            </table>
        </td>
    </tr>
</table>

Answer №1

If my son, you seek guidance in life.

To rearrange the table cells, consider using the css property direction. It can be applied to text or inline-block elements.

There are various ways to apply it.

<row dir="rtl">
<td dir="rtl">
.main-content {direction: rtl;  /* Right to Left */}

This code snippet showcases how the row or td could be utilized:

<!-- header -->
<container class="header">
  <row dir="rtl">
    <columns large="6" small="12" class="text-right" dir="rtl">
      <p class="text-right" style="color: #432a6f; font-size: 12px; text-decoration: underline;"><a href="<%@ include view='MirrorPageUrl' %>" target="_blank">View this email on the web</a></p>
    </columns>
    <columns large="6" small="12" dir="rtl">
      <a href="http://example.com" target="_blank"><img style="display: inline-block" border="0" alt="Image name" src="http://example.com/sample.png" width="184" height="45"></a>
    </columns>
  </row>
</container>
<!-- .header -->

Experiment with inheriting direction from parent elements, either rtl or ltr.

You may want to assign direction to a class for tables within a @media query to facilitate swapping in mobile view. Here's an example:

@media only screen and (max-width: 600px) {
  .leftColumnContent {direction: rtl}
}

For further insights on direction, visit: https://css-tricks.com/almanac/properties/d/direction/

Best wishes.

Answer №2

If you have the option to use nth-child, then consider implementing the following CSS:

.templateColumns:nth-child(2n) > tbody > tr > td:nth-child(1){
   float: right;
} 
.templateColumns:nth-child(2n) > tbody > tr > td:nth-child(2){
   float: left;
} 

Make sure to adjust your markup accordingly for push and pull to function correctly. Both the left and right columns should contain similar content.

I've assigned the class .templateColumns to the table in this CodePen example.

Keep in mind that not all email clients support nth-child selector, Gmail being one that does not support it.

Answer №3

This is the solution you've been searching for. I took one of your tables and demonstrated how to swap columns effectively. It's important to keep both elements together for it to function correctly.

The technique utilized here is a hybrid approach. Each column is constructed using divs enclosed in a td element.

<td valign="top" bgcolor="#FFFFFF" class="templateColumnContainer" style="padding:0px;text-align: center; vertical-align: top; font-size: 0px; direction:rtl;">

This specific td has a direction property set to "right to left" (direction:rtl) which affects everything inside the div.

Subsequently, each column is created using divs that are half the width of the container td.

<div style="width:100%;max-width:280px;display: inline-block; vertical-align: top; direction:ltr;">
</div>

These divs have a maximum width of 280px, 100% width, and a direction setting of "left to right" (direction:ltr).

All content within the div can be structured as a table with 100% width.

I also implemented what some refer to as "ghost columns." This involves an Outlook conditional statement indicating that this section is indeed a column.

For the second block of code, rearranging the divs will achieve the desired layout.

If any part of this explanation seems unclear or if you need further clarification, feel free to reach out.

Cheers!

Answer №4

The HTML dir attribute allows you to control the layout independently of the source order of each column.

If you design the email layout for mobile first, you can then adjust the desktop layout using the dir attribute. Below is an example of a two-column layout where the image will stack above the text on mobile, but be positioned in the right column on desktop:

<!-- The magic happens with dir=rtl (rtl = right to left). This switches the alignment on wider screens while maintaining stacking order on narrower screens. -->

<table dir="rtl" border="0" cellpadding="0" cellspacing="0" width="600" id="templateColumns">
    <tr>

        <!-- Place this column first in the source order to have the image stack above the text on mobile -->
        <td align="center" valign="top" width="50%" class="templateColumnContainer">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tr>
                    <td class="rightColumnContent" dir="ltr">
                        <img src="http://placekitten.com/g/480/300" width="280" style="max-width:280px;" class="columnImage" />
                    </td>
                </tr>
            </table>
        </td>

        <!-- Place this column second in the source order to have the image stack above the text on mobile -->
        <td align="center" valign="top" width="50%" class="templateColumnContainer">
            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                <tr>
                    <td class="leftColumnContent" dir="ltr">
                        <p style ="font-size:21px; color:#009DE0; width: 125px; line-height: 22px;";> Selección de profesionales en plantilla o freelance.</p>
                        <p style="font-size: 13px; line-height: 19px; width: 218px;"> A partir de un Job description acordado con el cliente, procedemos a entrevistar y a validar técnicamente a los candidatos que cumplan con los requisitos técnicos y personales, previamente establecidos.</p>
                    </td>
                </tr>
            </table>
        </td>

    </tr>
</table>

Your existing media query to stack the columns should seamlessly integrate with this code.

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

`Shaping up bootstrap spans with CSS`

I am working on a simple bootstrap layout for a workday scheduler app, and I've noticed that when the width of the text content increases it affects the vertical alignment of the spans where I display the hours of the day. Here is an image to illustra ...

HTML forms default values preset

I need help with pre-setting the values of a dropdown menu and text box in an HTML form for my iPhone app. When the user taps a button, it opens a webview and I want to preset the dropdown menu and text field. Can someone guide me on how to achieve this? ...

What could be causing the JavaScript to malfunction when combined with PHP?

Attempting to retrieve search items from Twitter using PHP curl, process, and update them every second. For this basic version, the goal is to refresh the search results for "bieber" every second. The issue seems to arise from combining PHP with JavaScript ...

How can I add a comma to a number input field when the numbers reach one thousand?

When setting the minimum and maximum prices of products, I encountered an issue where entering 10.000 displayed as 10000. To automatically add a decimal point to numbers and display it correctly as 10.000, I attempted the following solutions: <input typ ...

There seems to be an issue with the functionality of Js .classList.add()

Currently, I am in the process of creating a simple movie site and am working on the home page. On the home page, there is a carousel. In CSS, I have hidden the visibility of all slides, and my plan is to create an array for all the slides in JavaScript an ...

Choosing and Duplicating Text in Angular

I'm attempting to give the user the ability to select a paragraph and copy it by clicking a button. However, my current code is not working as expected. I initially tried importing directives but encountered errors, prompting me to try a different met ...

Is there a way to consistently determine if the focus is currently activated? (Using Javascript and jQuery)

I am completely new to the world of Javascript and jQuery, and my JSFiddle is really showcasing the issue perfectly. http://jsfiddle.net/mkLsr/3/ My main goal is to have a search box text input automatically focused when the page loads, allowing users to ...

Customize the CSS class for adding extra spacing between the Controls

I have a User Control with 3 radio buttons and I need to add space between the buttons themselves, not between the button and its text. Can someone help me figure out how to add this space? Here is my User Control list: public class RadioButtonListAppointm ...

A guide to retrieving nested values from a JSON object using JavaScript

Having trouble accessing specific values from a heavily nested JSON content returned by a URL? You're not alone! Many tutorials only cover simple nesting examples. Take a look at the code snippet I've been working on: $(document).ready(function ...

When clicked, the size of a link will adjust

Having trouble with my code and CSS. The pagination in Vue is working fine, but the links are changing size on certain pages. When clicking on the first or second number, the links remain the same size. However, when clicking on the third or fourth link, ...

Complete the form by entering data into multiple fields sharing the same identifier

Is there a way to send multiple dropdown values with the same name and have them inserted into the database? Any assistance would be greatly appreciated. <?php session_start(); require_once('Connections/koneksi.php'); if($_REQUEST['sub ...

Bring div button on top of the contenteditable field

I am working on an Angular app for a client and need to implement a clickable button at the bottom right of a contenteditable element, similar to the image shown below : https://i.sstatic.net/J6XdW.png The challenge is that the content needs to be scroll ...

jQuery increment value specifically upon click of a div

Is there a way to increase the value by clicking on the plus or minus picture? Everything works perfectly when there is only one "item_quantity" block on the page. However, things start to go wrong when I try to add another "item_quantity" block. This is ...

How can I make jQuery hide only the specific div when the close button is clicked?

After retrieving data from the database using a foreach loop, I have the following markup: <div id="announcment-wrap"> <div class="announcement-text"> This is again a dummy <a href="http://www.google.com">|&nbsp;click he ...

Unexpected behavior with HTML Bootstrap's dl-horizontal layout

Despite having the div class "dl-horizontal" within the table, the dl-horizontal fields are displaying outside the table. Here is the code I used: <!DOCTYPE html> <html lang="en> <head> <title>Bootstrap Example</title> ...

Retrieve JSON data from Form Submission

While I am not a front end developer, I have been trying my hand at it recently. I hope that the community here can assist me with an issue I am facing. I have a form that is supposed to send files to a server-side API like shown below: <form id="uploa ...

Leveraging the Angular (2) routerLinkActive directive to handle dynamic routes

Although my current approach works, I believe there may be a more efficient way to implement this in Angular. The situation is as follows: Imagine nested, inflected paths like /logos and /logo/:id The markup below functions as intended: <li class ...

Bring your text to life with animated movement using HTML5 and/or CSS3

My goal is to have a snippet of text, like "Lorem Ipsum..." slide horizontally into a colored DIV quickly, then smoothly come to a slow stop, continue moving slowly, speed up again, and exit the DIV - all while staying within the boundaries of the DIV. I ...

Adjust CSS to properly position links alongside details summary

Currently enhancing my Hugo site (repository link is here). I am aiming to integrate a details element alongside anchors, maintaining a consistent style. The desired layout is depicted in the initial screenshot where "abstract" serves as the details elemen ...

The replace method in JavaScript can only be used once

I'm trying to find a way to swap one string (str1) with another string (str2) whenever str1 appears in a particular div. Here's what I have managed to come up with so far: <script type="text/javascript"> $(window).load(function(){ var s ...