center align adsense on WordPress

I have a Google AdSense element on my WordPress but as default it is left aligned. How can I make it center align on the horisontal axis?

The code I have tried is:

<div style="margin:auto">  
    //AdSende Script
</div>

Related posts

Leave a Reply

5 comments

  1. Add adsense code under center tag..or in table

    <center>Adsense code here</center>
    

    or
    add table

    <table width="100%">
      <tr>
        <td align="center">Adsense code here</td>
      </tr>
    </table>
    
  2. What if you try something like the following:

    <div class="textwidget">
      <div class="adsense">  
        //AdSense Script
     </div> <!-- .adsense !-->
    </div> <!-- .textwidget !-->
    

    And in your CSS:

    .textwidget {text-align: center;}
    .adsense {margin:0 auto;}
    
  3. This is what works for me. Tested!
    Margin auto is fine but it needs a width to work. So:

    <div style="max-width:400px;margin:auto">adsense code here</div>
    

    Note: adjust width as necessary.

    I successfully center adsense ads like this.