demosthenes.info

I’m Dudley Storey, the author of Pro CSS3 Animation. This is my blog, where I talk about web design and development with , and . To receive more information, including news, updates, and tips, you should follow me on Twitter.

featured articles

popular favourites

CSS Positioning: fixed

LEVI'S

This is an example of an element with position: fixed; applied to it, for this blog's article on the CSS property.

As background-attachment: fixed is to background images, position: fixed is to elements: it allows an element to be fixed in position on the page, allowing the rest of the page content to scroll past it. It is usually (but not exclusively) applied to divs, and is part of the “Web 2.0” aesthetic: fixed headers and footers, for example. As with elements positioned absolute, ordinary static content will scroll underneath any fixed content.

One example is a “pull tab” on the side of the page, which keeps content out of the way until needed. (I have added a effect for modern browsers.)

While I will leave the interactivity of such a feature to another article, positioning the tab itself is very easy. The markup would be:

  1. <div id=”fixed-pull-tab”>
  2. <img src=”assets/images/red-tab.png” style=”float: right” alt=”LEVI’S”
  3. title=”LEVI’S” />
  4. <p>This is an example of an element with <code>position: fixed;</code> applied
  5. to it, for this blog’s article on the CSS property.</p>
  6. </div>

And the associated CSS – I have used box-shadow on the image to emphasize the “layer above” nature of the fixed position div:

  1. div#fixed-pull-tab { width: 300px; border: 1px solid #000;
  2. padding-left: 1em; background-color: rgba(255, 255, 37, 0.7);
  3. position: fixed; left: -265px; top: 200px; }
  4. div#fixed-pull-tab p { margin-right: 70px; }
  5. div#fixed-pull-tab img {
  6. -webkit-box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.33);
  7. -moz-box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.33);
  8. box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.33); }
  9. div#fixed-pull-tab:hover { left: 0; }

As with position: absolute, position: fixed should be used carefully: the property makes it all too easy to create web page features that overlap and obscure page content.

You must be signed up in order to leave comments.

web developer guide

featured comment

by Aisling Brock in New Business Card Design

what i'm reading

A Feast for Crows: A Song of Ice and Fire: Book Four
A Feast for Crows: A Song of Ice and Fire: Book Four

what i'm watching

Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]
Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]

what i'm playing

Borderlands
Borderlands

what i'm hearing

Planets
Planets

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.