Old 07-04-2006   #1 (permalink)
Be Unique. Be Heard.
 
Jacorre's Avatar
 
Join Date: Jul 2006
Location: USA
Posts: 489

Thumbs up [CSS] Absolutely Positioned Ads

The best areas to place advertising can vary from page to page and it depends on the type of content and layout you have. But one element that all websites have in common is a header and it's the first thing that visitors usually see. For that reason, it's a great spot to place advertisements.

If you're following the new trend to lay out your site with CSS, you're not using tables. So how do you position the ad in a specific area? Let's learn how to absolutely position an ad!

STEP ONE

Let's say we have a header image that's 800 pixels wide and 140 pixels tall. (The following image isn't that size as you can tell but let's pretend!)



STEP TWO

We'll place it in a div called header and make it the background image. The CSS for that would be as follows:

HTML Code:
#header {
height: 140px;
width: 800px;
background-image: url(images/header.gif);
position: relative;
}
The XHTML for that would be as follows:

HTML Code:
<div id="header"></div>
STEP THREE

Let's say we have an ad that's 234 pixels wide and 60 pixels tall. I want to place it in the bottom left corner of the header. I don't want it to be right against the border so I want a bit of space in between the left and bottom sides.



STEP FOUR

We'll place the advertisement in a div called ad. The CSS for that would be as follows:

HTML Code:
#ad {
height: 60px;
width: 234px;
position: absolute;
left: 10px;
bottom: 10px;
} 
The XHTML for that would be as follows:

HTML Code:
<div id="ad"></div>
Now let's bring it all together by placing the ad inside the header:

HTML Code:
<div id="header">
<div id="ad"></div>
</div> 
So how does it work? Good question. Let me point out the details of the CSS that makes it work:

#header {
height: 140px;
width: 800px;
background-image: url(images/header.gif);
position: relative;
}

#ad {
height: 60px;
width: 234px;
position: absolute;
left: 10px;
bottom: 10px;

}

Notice that the ad's position is set to absolute and the header's position is set to relative. What that means is that we want the ad to be absolutely positioned relative to where the header is.

We said the header was 800 pixels wide and 140 pixels tall. That means that the width of the header starts at 0 pixels and ends at 800 pixels. The height starts at 0 pixels and ends at 140 pixels.

Because we set the ad's position of left and bottom to 10 pixels, the ad is positioned 10 pixels from the left and 10 pixels from the bottom of the header! Need a live example, check out the ad inside the header on this page!

NOTE: The options you have to position are top, right, bottom, and left. So if you wanted to position the ad in the top left, it would be top: 10px and left: 10px.

Go have some fun absolute positioning!
__________________

Jacorre Studios Blog

Last edited by Man1c M0g; 07-04-2006 at 12:27 AM.
Jacorre is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 07-04-2006   #2 (permalink)
Be Unique. Be Heard.
 
Jacorre's Avatar
 
Join Date: Jul 2006
Location: USA
Posts: 489

Could someone help with getting the xhtml div information to appear? I wrapped code tags around it but I think it thinks it's real code instead of just text? Thanks!
__________________

Jacorre Studios Blog
Jacorre is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 07-04-2006   #3 (permalink)
Sheep Worrier
 
Man1c M0g's Avatar
 
Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,073
Blog Entries: 14

Send a message via ICQ to Man1c M0g Send a message via MSN to Man1c M0g Send a message via Skype™ to Man1c M0g
Hmmm. Vbulletin can be very wierd when it comes to code. Any chance you can send me the tutorial as a TXT to mog-at-mogsoft.com? It'll be much easier to pop online then.

Edit: - Nevermind, I realized that you need to use the [ HTML ] tag to display HTML - the [ CODE ] tag messes up. All sorted now tho.
__________________
Man1c M0g is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 07-04-2006   #4 (permalink)
Be Unique. Be Heard.
 
Jacorre's Avatar
 
Join Date: Jul 2006
Location: USA
Posts: 489

Great, thanks! I will keep that in mind for future posts using html.
__________________

Jacorre Studios Blog
Jacorre is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 07-04-2006   #5 (permalink)
Eternal Being
 
Join Date: Feb 2006
Location: Finland
Posts: 239

why is there \" on the code? Seems like code executed within php code or is part of the vbulletin problem? Good tutorial so thanks for contributing.
__________________
Telos is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 07-04-2006   #6 (permalink)
Be Unique. Be Heard.
 
Jacorre's Avatar
 
Join Date: Jul 2006
Location: USA
Posts: 489

The code wasn't appearing. I think it was actually trying to create a div there instead of just typing the text. By adding a slash it finally appeared. If you know of a better way to display it, let me know! I'd rather not do it this way because the code is technically wrong and shouldn't have that slash there.
__________________

Jacorre Studios Blog
Jacorre is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 07-11-2006   #7 (permalink)
Sheep Worrier
 
Man1c M0g's Avatar
 
Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,073
Blog Entries: 14

Send a message via ICQ to Man1c M0g Send a message via MSN to Man1c M0g Send a message via Skype™ to Man1c M0g
This tutorial is now online over @ http://www.biorust.com/tutorials/detail/233/en/ . Really easy to upload too! Many thanks for all your hard work Jacorre!
__________________
Man1c M0g is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[CSS] Layout Yao HTML / PHP / ASP / JS 6 05-19-2006 09:50 PM


All times are GMT +1. The time now is 12:28 PM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT