Thursday, 8 February 2007

HTML for AdSense Publishers: Aligning Left, Right and Center

This is the first in a series of posts intended to provide AdSense publishers (and, indeed, anyone else using other similar services) with some basic HTML knowledge that will help them display their ad units correctly.

This first post looks at how to align your ads to the left and right and how to center the ads.

Left Aligning

Left aligning is the default way that ads will be displayed, however, if your ad unit is contained inside a page element that is centering or right-aligning its content, you will need to manually left-align. To do so, you can implement either of the following methods:

1) The old-fashioned and now "deprecated" method is as follows

<div align="left">
... your code goes here ...
</div>
2) The better way to do it, using styles is
<div style="text-align:left;">
... your code goes here ...
</div>
(Alternatively, if you're familiar with CSS and external style sheets, you can simply assign a class to the div tag that has a style of text-align:left - but that's another lesson for another day!)

Right Aligning

Right aligning is basically the same as left-aligning, only you simply replace left with right!

1) Thus, the old-fashioned method is:
<div align="right">
... your code goes here ...
</div>
2) Or the better way to do it, using styles is
<div style="text-align:right;">
... your code goes here ...
</div>
Centering

Again, centering is basically the same as left-aligning, only you simply replace left with center!

1) Old-fashioned method is:
<div align="center">
... your code goes here ...
</div>
2) Or the better way to do it is:
<div style="text-align:center;">
... your code goes here ...
</div>
Note: These techniques only align the ads within another page element. If you want the ads to be on the left or right but have other content wrap around them, you need to "float" them ... which will be the subject of the next post in this series.

3 comments:

Blogger said...

Thanx... It really helped....

I couldnt align my head section....

Credit goes to you..

Nabeeha

paying ptc sites said...

But what if i put 2 ads and i want them one on right other on left
it shows but in different rows

Sturla Slanketips said...

If I want to place the ad to the left and then i littlebit up? How do I do that? Vertical aligment/placement?