spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / column2
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Logo

CSS positioning:
many objects occupying the same space


The keys to our technique are:


All of these features are provided by Cascading Style Sheets, through the new positioning properties. For those unfamiliar with CSS, several introductory articles on this site will very quickly bring you up to speed.

Recall that a CSS rule is defined by a selector and a declaration:

A CSS declaration is, in turn, defined by a property and a corresponding value.

And, finally, a CSS rule can host many declarations, separated by semi-colons:.

Positioning Properties

We can control the position of our HTML by enclosing it in a container tag such as <DIV> or <SPAN>, with a unique ID, and defining a CSS rule for this contained HTML in our stylesheet. There are other ways, without containers, particularly in Explorer, but it is best to get used to this method first.

A good rule to follow: Use <DIV> for block-level elements (requiring a new line before and after) and <SPAN> for inline elements (rendered on same line as preceding and following HTML).

In our document, we now add the following:

And our stylesheet reads:

The hash (#) designates a unique identifier to be used only once in the document. It should be avoided in CSS rules for tags or any non-positioned containment.

Our position property has the value relative because we want our image map to fall relative to the flow of the document. In fact, up to this point, we have done nothing unordinary. Our image is positioned exactly where it would have been even without CSS. Then, why do it?

Every positioned element establishes a new x-y coordinate system for all contained HTML within that element. New positioned elements can now be inserted within the DIV and positioned exactly in relation to our image map.

Nested Elements

With the above in mind, we can now enclose each of the images we have created in new absolutely positioned elements:

Now, reflect these modifications in the stylesheet:

Both our images are now occupying the same physical space: They are both at the top left corner of the elMenu element. Since menuover.gif was referenced last, it was placed last, blocking out our image map.

Visibility

By adding the visibility property, we can control which of the two images is initially visible.

Now that we have positioned two images, one on top of the other, and hidden one of them, we must find a way to display the hidden image on demand.


Produced by Peter Belesis and

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

All Rights Reserved. Legal Notices.
Created: 08/06/97
Revised: 10/16/97

URL: http://www.webreference.com/dhtml/column2/CSSpos.html