CSS Positioning Properties
The position property takes one of four values (of which static is the default) and allows the stylist to
place any element anywhere in the layout.
More importantly, the assignment of any position value other than static alters the positioning context of
elements, which is briefly described in Chapter 3.
How Positioning Works
Consider the following values:
#someDiv { ... left: 160px; top: 96px; }Suppose that those styles are applied to the following markup:
... <body><div id="main"> ... <div id="someDiv">The quick red fox jumps over the lazy brown dog.</div> ... </div></body>
The four position values
that can be applied to #someDiv will yield the following
results:
staticleftandtopvalues are not applied; the element retains its expected position in the layout flow of the document.absoluteThe upper-left corner of
#someDivappears 96 pixels below and 160 pixels to the right of the upper-left corner of the browser canvas. The margin applied tobodyis disregarded. The element is removed from the layout flow of the document.fixedYields the same result as
position: absolute, except that the element will retain its position on the browser canvas regardless of any content scrolling. The element is removed from the layout flow of the document.relativeInstead of being offset from the upper-left corner of the browser canvas,
#someDivis offset from where it would normally appear in the document layout. The element retains its expected position in the layout flow of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access