AdSense Positioning using CSS

Status
Not open for further replies.

BNWFinance

$100/day in 100 days.....
Aug 10, 2006
146
1
0
Margaritaville
www.myfinanceforum.com
I'm trying to position an adsense block using HTML/CSS inside some text. I want the text to "wrap" around the adsense block. Without getting into too many details, the article text is called from a file for inclusion separately (and this is where the problems start). I've tried position:absolute/relative combined with float parameters on both the text block and the adsense block.

I can get the adsense block where I want it, but it blocks out the underlying article text.

Any ideas from you HTML/CSS gurus out there?
 


Code:
<div style="float: right; margin: 0px; margin-top: 20px; padding-left: 5px" class="noprint">
<script type="text/javascript"><!--
google_ad_client = "pub-666";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_type = "text";
google_ad_channel ="";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "000000";
google_color_url = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<h1>Meso</h1>
<p>Text txt text xxx</p>
<p>sadgsdg</p>
<p>sgasdgsdg</p>
<p><strong>High paying keywords</strong></p>

That's one way to do it.
 
Hi joe, thanks for the reply. Unfortunately, I wish it were that simple. Perhaps an example of my code would help (note: most of this is NOT the actual code, but will give you an idea of what I'm trying to do):
Code:
<?php include('article.txt'); ?>
<div style="?">
<!--ADSENSE CODEBLOCK-->
</div>
The ? is where I've been trying everything - float, position, word-wrap...All to no avail. I can get the block in the right place using 'position' elements, but it appears in the foreground, over the article text.

Some might argue this is a good thing - who cares about the article anyhow so long as they click the damn ad, but I'm not quite that far over to the "dark side" yet.
 
BNWFinance-

The problem has to do with where you are telling AdSense to be placed. Essentially, in order to get the effect that you are talking about, you need to call Adsense from within the article itself.

Here is a way to do this. Since you are using php, first take your adsense block code and throw it into a variable, along with a div that floated left.

First let's setup the CSS. Put this in the header:

Code:
 <style type="text/css">
#container { width:600px; margin-left:auto; margin-right:auto; }
#adsense { float: left; margin:2px; }
</style>
Now, let's setup a php variable that contains a div and the adsense block:

Code:
 <? 
$adsense = '<div id="adsense">
<script type="text/javascript"><!--
wickedfire_ad_client = "pub-3667831486677476";
wickedfire_ad_width = 336;
wickedfire_ad_height = 280;
wickedfire_ad_format = "336x280_as";
wickedfire_ad_type = "text_image";
//2007-01-19: Redbox Codes
wickedfire_ad_channel = "5419184216";
//--></script>
<script type="text/javascript"
  src="show_ads.js">
</script>
</div>';  
?>
Great, now we've got a variable that will display an adsense block anytime you call $adsense in php. Next, you need to add that simple string $adsense somewhere in your article text, most probably near the top after the first 1 - 3 sentences. So your article.txt may look something like this:

Have you ever tried widgets? I have, and I think that green widgets are the best. $adsense There are many different types of widgets and one must take many different things into account when evaluating widgets for their own personal use.
PHP will throw the adsense block right in the middle of the article, and since it's floated to the left, the text will wrap around to the right.

I've setup an example for you here, feel free to peak around at the code and how it looks after it's rendered:

WickedFire Test

Let me know if you have any questions...
 
Status
Not open for further replies.