Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

Positioning Schemes 291

11


Elements are positioned relative to their containing block. A containing block is the
block-level element that’s the ancestor of the positioned element. In the example you just
saw, the page’s element is the containing block for the paragraphs. Let’s say I
add a new style to the page’s style sheet:


#positioned { position: relative; left: 50px; }


Then I put the three paragraphs in the preceding example in a new

:



... the three paragraphs above ...

All three paragraphs will be moved 50 pixels to the right, and the offset paragraph will be
positioned relative to the

that is its containing block.


In addition to containing blocks, there are also anonymous blocks. Browsers automati-
cally create anonymous blocks when a block-level element appears within a containing
block along with inline elements. Here’s an example:



This content is inside an anonymous block.

This is a paragraph.


This content is also inside an anonymous block.

FIGURE 11.2
Transparency of
overlapping ele-
ments.