positionと包含ブロックの関係

 
ビジュアル
ホーム > CSS2 Note > position > positionと包含ブロックの関係

初期包含ブロック(ルート要素)との関係

*1 CSS2における初期包含ブロック(initial containing block)とは、親要素を持たない要素をあらわします。ツリー構造におけるルート要素とは、HTML、XHTMLにおいては、html要素(document root element)のことを指します。

*2 通常、包含ブロックの左上が座標の0の点になります(CSS2仕様書では明文化されていません)。絶対配置において、包含ブロックがインライン要素の場合、文字方向が左→右のとき、包含ブロックの左上が座標の0の点になり、右→左のときは右上が基点となります。
 

staticな包含ブロック(block)との関係

/* static 包含ブロック (block) */
div.outer_stat {position:static; border:dotted 8px #9cf; padding:10px;}
div.outer_rela {position:static; border:dotted 8px #cc6; padding:10px;}
div.outer_abso {position:static; border:dotted 8px #9c6; padding:10px;}
div.outer_fixe {position:static; border:dotted 8px #f66; padding:10px;}
 

staticな包含ブロック(inline)との関係

/* static 包含ブロック (inline) */
span.outer_stat {position:static; border:dotted 2px #9cf; padding:10px;}
span.outer_rela {position:static; border:dotted 2px #cc6; padding:10px;}
span.outer_abso {position:static; border:dotted 2px #9c6; padding:10px;}
span.outer_fixe {position:static; border:dotted 2px #f66; padding:10px;}
 

relativeな包含ブロック(block)との関係

/* relative 包含ブロック (block) */
div.outer_stat {position:relative; top:30px; left:30px; border:dotted 8px #9cf; padding:10px;}
div.outer_rela {position:relative; top:30px; left:30px; border:dotted 8px #cc6; padding:10px;}
div.outer_abso {position:relative; top:30px; left:30px; border:dotted 8px #9c6; padding:10px;}
div.outer_fixe {position:relative; top:30px; left:30px; border:dotted 8px #f66; padding:10px;}
*3 ie6まではfixedに未対応です。またie7には、fixedにおいて隅のボーダーが隠れてしまうバグがあります。このバグはie8では修正されています。
 

relativeな包含ブロック(inline)との関係

/* relative 包含ブロック (inline) */
span.outer_stat {position:relative; top:30px; left:30px; border:dotted 2px #9cf; padding:10px;}
span.outer_rela {position:relative; top:30px; left:30px; border:dotted 2px #cc6; padding:10px;}
span.outer_abso {position:relative; top:30px; left:30px; border:dotted 2px #9c6; padding:10px;}
span.outer_fixe {position:relative; top:30px; left:30px; border:dotted 2px #f66; padding:10px;}
*3 ie6まではfixedに未対応です。またie7には、fixedにおいて隅のボーダーが隠れてしまうバグがあります。このバグはie8では修正されています。

*4 CSS2, CSS2.1の仕様書では、staticおよびrelativeの包含ブロックは、「ルート要素(html)かつ絶対配置、固定配置がなされている要素、および最も近い祖先ブロック要素」とされています。しかしながら、現状ではie7 ie8 ff3 o9 sf4 gc2においてrelativeが指定されているインライン要素が包含ブロックとなります。
 

absoluteな包含ブロック(block)との関係

/* absolute 包含ブロック (block) */
div.outer_stat {position:absolute; top:30px; left:30px; border:dotted 8px #9cf; padding:10px;}
div.outer_rela {position:absolute; top:100px; left:30px; border:dotted 8px #cc6; padding:10px;}
div.outer_abso {position:absolute; top:300px; left:30px; border:dotted 8px #9c6; padding:10px;}
div.outer_fixe {position:absolute; top:400px; left:30px; border:dotted 8px #f66; padding:10px;}
 

absoluteな包含ブロック(inline)との関係

/* absolute 包含ブロック (inline) */
span.outer_stat {position:absolute; top:30px; left:30px; border:dotted 2px #9cf; padding:10px;}
span.outer_rela {position:absolute; top:100px; left:30px; border:dotted 2px #cc6; padding:10px;}
span.outer_abso {position:absolute; top:300px; left:30px; border:dotted 2px #9c6; padding:10px;}
span.outer_fixe {position:absolute; top:400px; left:30px; border:dotted 2px #f66; padding:10px;}
 

fixedな包含ブロック(block)との関係

/* fixed 包含ブロック (block) */
div.outer_stat {position:fixed; top:30px; left:30px; border:dotted 8px #9cf; padding:10px;}
div.outer_rela {position:fixed; top:100px; left:30px; border:dotted 8px #cc6; padding:10px;}
div.outer_abso {position:fixed; top:200px; left:30px; border:dotted 8px #9c6; padding:10px;}
div.outer_fixe {position:fixed; top:300px; left:30px; border:dotted 8px #f66; padding:10px;}
 

fixedな包含ブロック(inline)との関係

/* fixed 包含ブロック (inline) */
span.outer_stat {position:fixed; top:30px; left:30px; border:dotted 2px #9cf; padding:10px;}
span.outer_rela {position:fixed; top:100px; left:30px; border:dotted 2px #cc6; padding:10px;}
span.outer_abso {position:fixed; top:200px; left:30px; border:dotted 2px #9c6; padding:10px;}
span.outer_fixe {position:fixed; top:300px; left:30px; border:dotted 2px #f66; padding:10px;}
 
関連項目: positionのレンダリング | positionと包含ブロックの関係 | position | top right bottom left | 包含ブロック
トップページ CSS2 Note ページトップ
 2008/09/08発行 2011/06/14更新