Pietro Lungarini
Pietro Lungarini

Reputation: 181

Responsive boxes in HTML Email

I use ActiveCampaign to send my emails, and recently I started building HTML emails to have better control of the situation.

ActiveCampaign automatically sets tables, so I don't need to worry about it, as it conforms a standard HTML to an email HTML.

I should have a responsive row with columns that wrap themselves once the user views the email on a mobile phone.

I'm trying to build some columns inside the email, I tried with flexbox but it constantly giving me errors in Gmail. I even tried with but it does not wrap content.

Here you can find the full code. I highlighted the part where I have issues.

.divmain {
  margin: 5px;
  border-radius: 5px;
  -moz-box-shadow: 0px 0 7px 0px #b5b5b5;
  -webkit-box-shadow: 0px 0 7px 0px #b5b5b5;
  box-shadow: 0px 0 7px 0px #b5b5b5;
}

.divp {
  background-image: url("http://i67.tinypic.com/jhzs0g.png"), linear-gradient(90deg, #FD8571, #EEBD7C);
  background-size: cover;
  background-position: bottom;
  background-repeat: no-repeat;
  width: auto;
  border-radius: 5px 5px 0px 0px;
  padding-left: 5%;
  padding-right: 5%;
  padding-top: 7%;
  padding-bottom: 7%;
  margin-bottom: 0;
  text-align: center;
}

.divs {
  background-image: url("http://i66.tinypic.com/350w10h.png"), linear-gradient(90deg, #7172fd, #bc7cee);
  background-size: cover;
  background-position: bottom;
  background-repeat: no-repeat;
  width: auto;
  border-radius: 0px 0px 5px 5px;
  padding-left: 5%;
  padding-right: 5%;
  padding-top: 7%;
  padding-bottom: 7%;
  margin-bottom: 0;
  text-align: center;
}

.divw {
  width: auto;
  padding-left: 7%;
  padding-top: 5%;
  padding-bottom: 1%;
  padding-right: 27%;
  text-align: left;
  border-style: solid;
  border-width: 0px 1px 0px 1px;
  border-color: #cecece;
  margin: 0;
}

.row {
  display: flex;
  justify-content: center;
  flex-flow: row wrap;
}

.column {
  flex: 33.33%;
  padding-left: 5%;
  padding-right: 5%;
  margin-bottom: 5%;
  margin-left: auto;
  margin-right: auto;
}

.columnbox {
  width: auto;
  border-radius: 8px;
  padding: 5%;
  text-align: center;
  border-style: solid;
  border-width: 1px;
  border-color: #cecece;
  -moz-box-shadow: 0px 0 7px 0px #b5b5b5;
  -webkit-box-shadow: 0px 0 7px 0px #b5b5b5;
  box-shadow: 0px 0 7px 0px #b5b5b5;
}

.row::after {
  content: "";
  clear: both;
  display: table;
}

.border-div {
  border-style: solid;
  border-width: 0px 1px 0px 1px;
  border-color: #cecece;
  border-radius: 0 0 3px 3px;
}
<!DOCTYPE html>
<html>

<head>
</head>

<body>

  <div class="divmain">

    <div class="divp">

      <h1 style="color:white; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em">Sei della Famiglia adesso!</h1>

      <p style="font-size: 1.4em; color: white; line-height: 150%;  font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-top: 0; padding-top: 0">Moover non è un semplice servizio,<br> è una fantastica community!
      </p>

      <div class="btn" style="background-color: #4E69C2; text-decoration: none; display: inline-block; border: 3px solid #4E69C2; border-radius: 7px; font-size: 1.4em; padding: 0.3em 1em; -webkit-font-smoothing: antialiased; color: #fff;"><a class="btn-link" href="https://moover.digital/" rel="noopener noreferrer" style="text-decoration: none; color: #fff; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; font-size: 0.8em; font-weight: 600; -webkit-font-smoothing: antialiased;"
          target="_blank">Scopri di più ►</a></div>

    </div>

    <div class="divw">

      <p style="font-size: 1.1em; line-height: 150%; color: #3b3b3b; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif"><b>Oh! Eccoti!</b><br> Volevamo informarti che il servizio di Crescita Organica è stato attivato con successo sul profilo @%USERNAME%
      </p>

      <p style="font-size: 1.1em; color: #4E69C2; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em;"><b>Il periodo di Prova Gratuita durerà 7 giorni!</b>
      </p>

      <p style="font-size: 1em; line-height: 150%; color: #3b3b3b; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-top: 0; padding-top: 0;">(Goditeli fino in fondo!)
      </p>

    </div>


    <!-- Here is where I have some problems -->


    <p class="border-div" style="margin: 0; text-align: center; font-size: 1.2em; line-height: 150%; color: #3b3b3b; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; font-weight: bold; padding-bottom: 1em; padding-top: 1em; ">Questi sono alcuni dati attuali del tuo account</p>

    <div class="row border-div desktop-view" style="padding-top: 1em; padding-right: 5%; padding-bottom: 3em; padding-left: 5%;">

      <div class="column">

        <div class="columnbox" style="margin-right: 5%;">
          <p style="font-size: 1em; color: rgb(78, 194, 136); font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em; font-weight: bold; margin-top: 0.2em;">Follower Attuali</p>
          <p style="font-size: 350%; color: #4E69C2; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em; font-weight: bold; margin-top: 0.2em;">99.000</p>
        </div>

      </div>

      <div class="column">

        <div class="columnbox" style="margin-right: 5%;">
          <p style="font-size: 1em; color: rgb(78, 194, 136); font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em; font-weight: bold; margin-top: 0.2em;">Likes Attuali</p>
          <p style="font-size: 350%; color: #4E69C2; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em; font-weight: bold; margin-top: 0.2em;">99.000</p>
        </div>

      </div>

      <div class="column">

        <div class="columnbox" style="margin-right: 5%;">
          <p style="font-size: 1em; color: rgb(78, 194, 136); font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em; font-weight: bold; margin-top: 0.2em;">Commenti Attuali</p>
          <p style="font-size: 350%; color: #4E69C2; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em; font-weight: bold; margin-top: 0.2em;">99.000</p>
        </div>

      </div>

      <div class="column">

        <div class="columnbox" style="margin-right: 5%;">
          <p style="font-size: 1em; color: rgb(78, 194, 136); font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em; font-weight: bold; margin-top: 0.2em;">Engagement Rate</p>
          <p style="font-size: 350%; color: #4E69C2; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em; font-weight: bold; margin-top: 0.2em;">99.000</p>
        </div>

      </div>

    </div>

    <!-- Here is where my problems finishes -->

    <div class="divs">

      <h1 style="color:white; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-bottom: 0; padding-bottom: 0.2em">Entra nell'Area Personale!</h1>

      <p style="font-size: 1.4em; color: white; line-height: 150%;  font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; margin-top: 0; padding-top: 0">Visita la tua Area personale cliccando qui.<br> Potrai tenere traccia dei tuoi risultati!
      </p>

      <div class="btn" style="background-color: #4E69C2; text-decoration: none; display: inline-block; border: 3px solid #4E69C2; border-radius: 7px; font-size: 1.4em; padding: 0.3em 1em; -webkit-font-smoothing: antialiased; color: #fff;"><a class="btn-link" href="https://app.moover.digital/analytics" rel="noopener noreferrer" style="text-decoration: none; color: #fff; font-family:Open Sans,Roboto,San Francisco,Helvetica,Arial,sans-serif; font-size: 0.8em; font-weight: 600; -webkit-font-smoothing: antialiased;"
          target="_blank">Visita la tua Area ►</a></div>

    </div>

  </div>

</body>

</html>

The result should be a responsive row that, on the desktop has 4 columns aligned in a unique row. In mobile, it should be a vertical row like in the screenshot below:

enter image description here

Unfortunately, this is not the result that I have, and I absolutely need some help, because in Gmail App from Mobile Phone this is what I got:

enter image description here

Upvotes: 0

Views: 1660

Answers (1)

user2958788
user2958788

Reputation:

A few points:

  1. Don't use flexbox in email unless you are confident with email coding in general. I've tweaked some of your code (expanding the flex:#%; to flex:0 0 #%; and adding a fallback width) and noticed I fixed some things so I don't think the implementation you've taken from front end is working in email clients as you would expect
    There are quirks and fixes you need to include for different email clients that you should be aware of. Google this for help, not sure of any articles in particular as I haven't bothered trying to shoe horn Flexbox into my emails. But some have so definitely do some searching and you'll find some help.
  2. The same goes with using divs in email. It can be done and many use them but you need to know how to make them work in say Outlook desktop clients etc. FYI, your email is completely broken in Outlook, including the latest versions I can see in Litmus which is Outlook 2019.
    You may not need to support Outlook and that is fine, but it's good to know.
  3. Invest in a testing platform. Litmus and Email On Acid being the top tools.
    That way you can build and test and ensure your emails are working where they need to.

Overall, just be really cautious with pulling front end techniques into email. They won't all work but there are some in the community who have found ways to make Flexbox, CSS Grid and a few other popular front end techniques, work in email so do some research and you'll have a guide to follow.

Personally, I don't see the need to use up to date techniques like this. Using the good old table structure works for the most part.
Don't get me wrong, I have fun and test out the latest innovations and build stuff for fun but I always go back to the old phrase 'if it ain't broke, don't fix it'.
Email code isn't pretty and it isn't perfect but it works for 99% of designs out there and it's personal preference to implement fancy techniques like Flexbox etc.

And always remember that you want to use a technique that is easy to maintain. You don't want to hit issues like these every single time you try to update. It's time consuming and can be frustrating when you just want to get an email out.

I hope you can find a resolution for this though. Either through someone helping you with your Flexbox implementation, finding blog posts on doing this in email or by starting from scratch with code you're more comfortable with / is better supported and is easier for people to debug for you.

Upvotes: 1

Related Questions