Forum Moderators: not2easy
I'm looking for a way to place two contextual ads in their own div at a specific position, e.g. half way down the pages. Can I use absolute positioning to make the real content flow around the ads in this div?
tttttttttttttttttttttt
ttttttttttttttttttttttt
tttttttttttttttttttttt
tttttttttttttttttttttt
ttttttttttt ad ad ad
ttttttttttt ad ad ad
tttttttttttttttttttttttt
ttttttttttttttttttttttt
ttttttttttttttttttttttt
I'd like to keep the text content untouched, i.e. add the ads on a site-wide basis.
Thanks, the_nerd
}
#addiv{
width:200px;
height:200px;
border:1px solid black;
float:right;
top:300px;
}
HTML-
<div id="outerdiv">
<!-- AD GOES HERE -->
<div id="addiv">Here is the ad</div>
text goes here.
</div>
The above will give you a right aligned ad at the top of the content with the text wrapping around it after it reaches the bottom of the box.
You could use a serverside language to insert
<div id="addiv">Here is the ad</div>
in a random spot inside of your text which would make it so text wraps around the top and bottom.
Can I use absolute positioning to make the real content flow around the ads in this div?
You can't use 'absolute' positioning because the element (advert) will be taken out of the flow of the page and your text will simply flow behind it. You will need to 'float' it (as supermanjnk describes above).
Usage:
<?php
$text = "my text";
$text = insertad($text);
echo $text;
?>
$arr = str_split($str, $len/2);
$text = $arr[0];
$text .= "<div class=\"addiv\">AD GOES HERE</div>";
$text .= $arr[1];
thanks for your help, but ....
this way I could easily cut html tags apart and spoil the whole thing. Pictures might not show, links wouldn't work, ....
Looks like I'd have to split the content into 2 or 3 parts by hand
Is there anything else in the card, using a floated div, that (wild guess) has an upper margin pushing it down - or something like that?
function insertad($str) {
$len = strlen($str);
$arr = explode("\n", $str);
$num = count($arr);
$text="";
for ($i=0; $i<$num; $i++){
$text .=$arr[$i];
if ($i == 2 ¦¦ $i == 4) //currenty shows an ad at the 2nd and 4th paragraph (assuming you only have new lines on new paragraphs)
$text .= "<div class=\"addiv\">AD GOES HERE</div>";
}
return $text;
}
Can you parse the document (XHTML?) using PHP? HHHmmmm, just think aloud.