Read CSS: The Definitive Guide, 3rd Edition Online

Authors: Eric A. Meyer

Tags: #COMPUTERS / Web / Page Design

CSS: The Definitive Guide, 3rd Edition (50 page)

BOOK: CSS: The Definitive Guide, 3rd Edition
12.14Mb size Format: txt, pdf, ePub
ads

There are two small variations to point out. In horizontal layout,
either
right
or
left
can be placed according to the static position if their values are
auto
. In vertical layout, only
top
can take on the static position;
bottom
, for whatever reason, cannot.

Tip

As of this writing, no version of Internet Explorer, including IE7, supports
the vertical-centering behavior of
auto
top
and bottom margins on absolutely positioned elements.

Also, if an absolutely positioned element's size is overconstrained in
the vertical direction,
bottom
is ignored.
Thus, in the following situation, the declared value of
bottom
would be overridden by the calculated value of
5em
:



element D


There
is no provision for
top
to be ignored if the
properties are overconstrained.

Placing and sizing
replaced elements

Positioning rules are different for nonreplaced
elements than they are for replaced elements. This is because replaced elements
have an intrinsic height and width, and therefore are not altered unless
explicitly changed by the author. Thus, there is no concept of "shrink to fit" in
the positioning of replaced elements.

The behaviors involved in
placing and sizing replaced elements are most easily expressed by a series of
rules to be followed in order:

  1. If
    width
    is set to
    auto
    , the used value of
    width
    is determined by the intrinsic width of
    the element's content. Thus, if the width of an image is 50 pixels, then the
    used value is calculated to be
    50px
    . If
    width
    is explicitly declared (that is,
    something like
    100px
    or
    50%
    ), then the width is set to that
    value.

  2. If
    left
    has the value
    auto
    in a left-to-right language, replace
    auto
    with the static position. In
    right-to-left languages, replace an
    auto
    value for
    right
    with the static
    position.

  3. If either
    left
    or
    right
    is still
    auto
    (in other words, it hasn't been replaced in a previous
    step), replace any
    auto
    on
    margin-left
    or
    margin-right
    with
    0
    .

  4. If, at this point, both
    margin-left
    and
    margin-right
    are still defined to be
    auto
    , set them to be equal, thus
    centering the element in its containing block.

  5. After all that, if there is only one
    auto
    value left, change it to equal the remainder of the
    equation.

This leads to the same basic behaviors we saw with absolutely
positioned nonreplaced elements, as long as you assume that there is an explicit
width for the nonreplaced element. Therefore, the following two elements will have
the same width and placement, assuming the image's intrinsic width is 100 pixels
(see
Figure
10-50
):


a frowny facestyle="position: absolute; top: 0; left: 50px; margin: 0;">

it's a div!


Figure 10-50. Absolutely positioning a replaced element

As with nonreplaced elements, if the values are overconstrained, the
user agent is supposed to ignore the value for
right
in left-to-right languages and
left
in right-to-left languages. Thus, in the following example, the
declared value for
right
is overridden with a
computed value of
50px
:


a frowny facestyle="position: absolute; top: 0; left: 50px; right: 125px; width: 200px;
margin: 0;">

Similarly,
layout along the vertical axis is governed by a series of rules that
state:

  1. If
    height
    is set to
    auto
    , the computed value of
    height
    is determined by the intrinsic height of
    the element's content. Thus, the height of an image 50 pixels tall is
    computed to be
    50px
    . If
    height
    is explicitly declared (that is,
    something like
    100px
    or
    50%
    ) then the height is set to that
    value.

  2. If
    top
    has the value
    auto
    , replace it with the replaced element's
    static position.

  3. If
    bottom
    has a value of
    auto
    , replace any
    auto
    value on
    margin-top
    or
    margin-bottom
    with
    0
    .

  4. If, at this point, both
    margin-top
    and
    margin-bottom
    are still defined to be
    auto
    , set them to be equal, thus
    centering the element in its containing block.

  5. After all that, if there is only one
    auto
    value left, change it to equal the remainder of the
    equation.

As with nonreplaced elements, if the values are overconstrained,
the user agent is supposed to ignore the value for
bottom
.

Thus, the following markup would have the results
shown in
Figure
10-51
:


onestyle="position: absolute;
top: 0; left: 0; margin: 0;">
twostyle="position: absolute;
top: 0; left: 60px; margin: 10px 0; bottom: 4377px;">
 threestyle="position: absolute;
left: 0; width: 100px; margin: 10px; bottom: 0;">
 fourstyle="position: absolute;
top: 0; height: 100px; right: 0; width: 50px;">
fivestyle="position: absolute;
top: 0; left: 0; bottom: 0; right: 0; margin: auto;">

Figure 10-51. Stretching replaced elements through positioning

BOOK: CSS: The Definitive Guide, 3rd Edition
12.14Mb size Format: txt, pdf, ePub
ads

Other books

Via Dolorosa by Malfi, Ronald
A Little Mischief by Amelia Grey
Everybody Knows Your Name by Andrea Seigel
Endlessly (Paranormalcy) by White, Kiersten
Binding Arbitration by Elizabeth Marx
Castle Murders by John Dechancie
The Door into Sunset by Diane Duane
The Human Body by Paolo Giordano
Torn by Cat Clarke
Schooled by Korman, Gordon