Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New HTML email rules: How to center without margin: auto?

As per new email rules (thanks Microsoft and Google) all margins are stripped from your HTML. So using margin: 0 auto is out for a solution.

The structure is:

<table>
  <tr>
    <td align="center">
      <a href="THIS IS THE ELEMENT I NEED CENTERED" style="display: block; width: 50%;">Button</a>
    </td>
  </tr>

Now I could add yet another table inside the td but it is already like the 2nd nested table and I'm hoping there is a different solution other then nesting another table. The align="center" doesn't work.

like image 270
o_O Avatar asked Dec 02 '25 22:12

o_O


2 Answers

Try this code, I'm using this code to send html email and it works fine for gmail, outlook

<table style="width: 100%;">
  <tr>
    <td style="text-align: center;">
      <a href="THIS IS THE ELEMENT I NEED CENTERED" style="display: inline-block; width: 50%;">Button</a>
    </td>
  </tr>
</table>

Also, you can check allow css property for html email here: https://www.campaignmonitor.com/css/

like image 96
Thi Tran Avatar answered Dec 04 '25 13:12

Thi Tran


Cuz CSS in email is dangerous... buh BAM. ;D

<table width="100%">
  <tr>
    <td align="center">
      <a href="THIS IS THE ELEMENT I NEED CENTERED">Button</a>
    </td>
  </tr>
</table>
like image 27
BlakePetersen Avatar answered Dec 04 '25 13:12

BlakePetersen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!