W3Schools

home HOME

DHTML Tutorial
DHTML HOME
DHTML Intro
DHTML CSS
DHTML DOM
DHTML Events
DHTML Summary

DHTML DOM
DOM Reference

DHTML Examples
DHTML Examples
DOM Examples

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Forum

Helping W3Schools

DHTML CSS Positioning (CSS-P)

previous next

CSS is used to style HTML elements.


Examples

Note: Most of the DHTML examples require IE 4.0+, Netscape 7+, or Opera 7+!

position:relative
How to position an element relative to its normal position.

position:relative
How to position all headings relative to their normal position.

position:absolute
How to position an element using an absolute value.

(You can find more examples at the bottom of this page)


Which Attributes can be Used with CSS-P?

First, the element must specify the position attribute (relative or absolute).

Then we can set the following CSS-P attributes:

  • left - the element's left position
  • top - the element's top position
  • visibility - specifies whether an element should be visible or hidden
  • z-index - the element's stack order
  • clip - element clipping
  • overflow - how overflow contents are handled

Position

The CSS position property allows you to control the positioning of an element in a document.

position:relative

The position:relative property positions an element relative to its current position.

The following example positions the div element 10 pixels to the right from where it's normally positioned:

div
{
position:relative;
left:10;
}

position:absolute

The position:absolute property positions an element from the margins of the window.

The following example positions the div element 10 pixels to the right from the left-margin of its containing block:

div
{
position:absolute;
left:10;
}


Visibility

The visibility property determines if an element is visible or not.

visibility:visible

The visibility:visible property makes the element visible.

h1
{
visibility:visible;
}

visibility:hidden

The visibility:hidden property makes the element invisible.

h1
{
visibility:hidden;
}


Z-index

The z-index property is used to place an element "behind" another element. Default z-index is 0. The higher number the higher priority. z-index: -1 has lower priority.

h1
{
z-index:1;
}
h2
{
z-index:2;
}

In the example above, if the h1 and h2 elements are positioned on top of each other, the h2 element will be positioned on top of the h1 element.


Filters

The filter property allows you to add more style effects to your text and images.

h1
{
width:100%;
filter:glow;
}

Note: Always specify the width of the element if you want to use the filter property.

The example above produces this output:

Header

Different Filters

Note: Some of the Filter properties will not work unless the background-color property is set to transparent!

Property Argument Description Example
alpha opacity
finishopacity
style
startx
starty
finishx
finishy 
Allows you to set the opacity of the element filter:alpha(opacity=20, finishopacity=100, style=1, startx=0, 
starty=0, finishx=140, finishy=270)
blur add
direction
strength
Makes the element blur filter:blur(add=true, direction=90, strength=6);
chroma color Makes the specified color transparent filter:chroma(color=#ff0000)
fliph none Flips the element horizontally filter:fliph;
flipv none Flips the element vertically filter:flipv;
glow color
strength
Makes the element glow filter:glow(color=#ff0000, strength=5);
gray none Renders the element in black and white filter:gray;
invert none Renders the element in its reverse color and brightness values filter:invert;
mask color Renders the element with the specified background color, and transparent foreground color filter:mask(color=#ff0000);
shadow color
direction
Renders the element with a shadow filter:shadow(color=#ff0000, direction=90);
dropshadow color
offx
offy
positive
Renders the element with a dropshadow filter:dropshadow(color=#ff0000, offx=5, offy=5, positive=true);
wave add
freq
lightstrength
phase
strength
Renders the element like a wave filter:wave(add=true, freq=1, lightstrength=3, phase=0, strength=5)
xray none Renders the element in black and white with reverse color and brightness values filter:xray;


Background

The background property allows you to select your own background.

background-attachment:scroll

The background scrolls along with the rest of the page.

background-attachment:fixed

The background does not move when the rest of the page scrolls.


More Examples

Visibility
How to make an element invisible. Do you want the element to show or not?

Z-index
Z-index can be used to place an element "behind" another element, using Z-index priority.

Z-index
Check that the elements now have changed their Z-index priority.

Cursors
Change the style of the mouse cursor with CSS.

Filters
Change the style of your headings using the filter property.

Filters on Images
The filter property can also be used on images, here are some filter examples which look good on images.

Watermark
A background picture that does not move when the rest of the page is scrolling.


previous next




Jump to: Top of Page or HOME or Printer Friendly Printer friendly page

W3Schools provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2008 by Refsnes Data. All Rights Reserved.

Validate Validate W3C-WAI level A conformance icon W3Schools was converted to XHTML in December 1999
SITE SEARCH
 
About W3Schools
W3Schools Forum
E Components
Ecommerce
Components
for ASP.NET
WEB HOSTING
$15 Domain Name
Registration
Save $20 / year!
UK Domain Names
UK Web Hosting

Alojamiento Web
Buy UK Domain Names
Register Domain Names
Cheap Domain Names
Cheap Web Hosting
Best Web Hosting
Domain Name Registration
PHP MySQL Hosting
Top 10 Web Hosting
Web Hosting Providers
Web Hosting Company
UK Reseller Hosting
Web Hosting
WEB BUILDING
Website Templates
Flash Templates
Website Builder
Internet Business Opportunity
Custom Programming
FREE Trial or Demo
Web Content Manager
Forms,Web Alerts,RSS
Ecommerce Software
XMLSpy XML Editor
Azbuz Blog
SHOPPING
UK Wholesalers
UK Wholesale
UAE Dubai Property
Private Student Loans
UK Dropshippers & Wholesalers Directory
EDUCATION
US Web Design Schools
HTML Exam
YELLOW PAGES
www.nettkatalogen.no
www.gulex.dk
www.gulex.se
www.gelbex.de
www.teloos.fi
www.teloos.fr
www.teloos.co.uk
www.teloos.at
www.teloos.de