demosthenes.info

A blog by Dudley Storey on , , , , , , and anything else that strikes his fancy.

featured articles

popular favourites

CSS Positioning: static, the default

Static Layout Example
A typical static layout

By default, every element on your page has position: static applied to it. For that reason, static almost never needs to be declared explicitly, unless it is required to undo another position value inherited from an earlier declaration.

static” does not mean that the element maintains its position on the page. In fact a better term for this value would be “fluid”. The default positional model for HTML elements means that things do not overlap on your page: every element pushes every other element around, adjusting to the size, resolution, and aspect ratio of the device on which it is displayed.

Let's take a simple example of page content:

  1. <body>
  2. <p><img src=”assets/images/pericles.jpg” style=”width: 231px; height: 366px;
  3. float: left; margin-right: 1em;” alt=”Bust of Pericles” title=”Bust of Pericles”>
  4. Pericles was a prominent statesman, orator, and naval general of Athens during
  5. the city-states's <q>Golden Age</q>, from 448BCE until his death in 429. Pericles
  6. was a promoter of the arts (particularly plays), architecture (it was under his
  7. patronage that the Parthenon was built), and the principles of democracy,
  8. but he was also an instigator of war: Pericles is widely held to be responsible
  9. for maneuvering Athens into the disastrous Peloponnesian War with Sparta.</p>
  10. </body>

In this example, every element reserves its own space. The image does not overlap the text, and the text is pushed away from the image. static elements remain in the “flow” of the document. Resizing the browser would cause the page width to narrow, and the paragraph lines to wrap around the image and push any content below it further down the page. This is a good thing: page content adapts to every screen size, aspect ratio and resolution easily, and nothing overlaps or obscures anything else.

Note that this “nothing overlaps, everything is fluid” behaviour is a general governing principle of position: static. There are a few exceptions: text will obviously be on top of any background image, fluid designs can be abandoned by implementing fixed widths on containing div elements, and elements can be overlapped or pushed off the page by applying negative margin to their CSS presentational rules. But in general, static rules hold.

Elements with position: static applied to them, either explicitly or by default, cannot have the properties we are about to discuss in the next entries (top, left, bottom and right) applied to them. Static elements can only be moved around by modifying the values of margin or padding, or by altering their position in the HTML code of the page. This is a perfectly acceptable and simple for the majority of designs.

web developer guide

featured comment

by JoelB in Goodbye, JQuery Validation: HTML5 Form Errors With CSS3

what i'm reading

A Storm of Swords: A Song of Ice and Fire: Book Three
A Storm of Swords: A Song of Ice and Fire: Book Three

what i'm watching

Californication: The Third Season
Californication: The Third Season

what i'm playing

Mass Effect 3 Collector's Edition
Mass Effect 3 Collector's Edition

what i'm hearing

Dub FX
Dub FX

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.