Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

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:

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

The XHTML for that would be as follows:

<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:

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

The XHTML for that would be as follows:

<div id="ad"></div>

Now let's bring it all together by placing the ad inside the header:

<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 located. 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!

- Tutorial written by Jacorre

Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments


There are no comments for this tutorial yet.
You can place a comment by clicking here.
Amazing Font Pack!

Featured Tutorialsmore

Semi-Transparent K...
Semi-Transparent K...
- Adobe Photoshop -
Energy Nova
Energy Nova
- Adobe Photoshop -
Hard-Edged Cel-Sha...
Hard-Edged Cel-Sha...
- Adobe Photoshop -
The Pattern Maker
The Pattern Maker
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links



Special Options
Printer Friendly Version
Forum Threads

Help Please :)
Author: Roosta
Posted: Mar 25th, 5:08am
Activity: 0 replies, 363 views
thank you
Author: HypepapyHer
Posted: Mar 24th, 9:18pm
Activity: 1 replies, 373 views
 Deactivate Account
Author: jerinian
Posted: Oct 02nd, 12:16pm
Activity: 1 replies, 1290 views
 changes....
Author: supertackyman
Posted: Sep 12th, 3:56am
Activity: 2 replies, 1576 views
Back again and with free webhosting :)
Author: ngz
Posted: Aug 14th, 4:50pm
Activity: 0 replies, 1422 views
Cartoon Crab 6 Legs Walk Run created in Blender
Author: patricia3d
Posted: Jun 19th, 1:58pm
Activity: 0 replies, 2468 views
HTML Form Post Array to PHP
Author: Space Cowboy
Posted: May 25th, 3:18pm
Activity: 1 replies, 2375 views
My blog where i create Digi Scrapbook
Author: claudya07
Posted: May 11th, 3:33pm
Activity: 0 replies, 15000 views
Blood Dripping from Letters
Author: patricia3d
Posted: Apr 05th, 4:37am
Activity: 0 replies, 3579 views
A New Designer has joined the ranks
Author: skates1
Posted: Mar 28th, 3:19pm
Activity: 2 replies, 3378 views
The hole in Photoshop
Author: Mars
Posted: Feb 13th, 9:28pm
Activity: 2 replies, 3830 views
Colour Swatch
Author: ebz7350
Posted: Jan 15th, 11:18am
Activity: 0 replies, 2641 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    441
Total Fonts:    4673