-2

I have the following html in one of my mails:

<center>
  <table class="button">
    <tbody>
      <tr>
        <td>
          <a href="#">Set Now</a>
        </td>
      </tr>
    </tbody>
  </table>
</center>

The problem is that on Gmail this Set Now button is properly centered but on Yahoo it is aligned to the left side. Here is picture that shows the problem:

enter image description here

sandyJoshi
  • 733
  • 9
  • 20
Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133
  • Possible duplicate of [What's the best way to center your HTML email content in the browser window (or email client preview pane)?](https://stackoverflow.com/questions/2857765/whats-the-best-way-to-center-your-html-email-content-in-the-browser-window-or) – sandyJoshi Dec 14 '17 at 17:00

4 Answers4

3

Try following code :

<td align="center">
    <a href="#">Set Now</a>
</td>`
sandyJoshi
  • 733
  • 9
  • 20
2

Nesting another <table> is safer than using <center>. This should cover all your bases:

<td style="text-align: center;">

    <table class="button" align="center" style="margin: auto">
        <tbody>
            <tr>
                <td>
                    <a href="#">Set Now</a>
                </td>
            </tr>
        </tbody>
    </table>

</td>
Ted Goas
  • 7,051
  • 1
  • 35
  • 42
1

Try with

<table class="button" width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
  <tr>
    <td width="100%" align="center">
      <a href="#">Set Now</a>
    </td>
  </tr>
</tbody>

Bidstrup
  • 1,597
  • 2
  • 16
  • 32
1

Set margin-left and margin-right to auto to the parent table. Like this,

<table class="button" style="margin-left:auto;margin-right:auto;">
<tbody>
  <tr>
    <td>
      <a href="#">Set Now</a>
    </td>
  </tr>
</tbody>

Although I must say that only styling the anchor tag to be a button is not going to work across all email clients, you probably should use code generated from here https://buttons.cm/