Ian Hoar – Passion for Technology – Geeking Out - Technology, Web, Toys, Games, Design, Entertainment, Gadgets, & Geeking Out

How to center Google AdSense ads

It took me awhile to figure out how to center Google AdSense ads. Searches showed that many other people were running into the same issue, so I thought I would share my method for centering.

At first I tried things like margin:auto, center and padding in a <div> wrapped around the ad, but nothing seemed to work. The reason for this is the AdSense box is absolutely positioned. The easy fix for this is to create a CSS class or inline style as shown below.

CSS class

.adSenseCenter {
	position:relative;
	width:120px;
	margin:auto;
}

Container <div>

<div class="adSenseCenter">
	adSense code goes here
</div>

Or quick and dirty inlines style.

<div style="position:relative; width:120px; margin:auto;">
	adSense code goes here
</div>

Don’t forget that the width of the <div> must equal the width of the adSense ad. Now you can center your ads.

17 Comments to “How to center Google AdSense ads”

Responses:

Your comments are important, join the conversation