背景画像の表示位置 (The background)

 
背景
ホーム > CSS2 Note > 背景画像の表示位置
C1- ie4- N6-

説明

background-position: position; C1- ie4- N6-
値:  [[ <%値> | <長さ> ]{1,2} | [[ top | center | bottom ] || [ left | center | right ]]] | inherit
初期値:0% 0%適用要素:ブロック要素置換要素継承:しない%値:ボックスサイズを参照メディア:ビジュアル
このプロパティは、背景画像が指定されている場合に、背景画像の表示位置を指定します。
 

使用例

body {
    background-image:url("logo.png");
    background-attachment:fixed;
    background-position:100% 100%;
    background-repeat:no-repeat
}

このように指定することで、一枚のロゴ画像を右下隅に表示させることができます。
 

背景画像の表示位置 <'background-position'>

%値 %値 C1- ie3- N6- 「0% 0%」という値は、画像の左上と、ボックスのパディング辺の左上を揃えます。「100% 100%」という値は、画像の右下と、ボックスのパディング領域の右下を揃えます。
長さ 長さ C1- ie3- N6- 「2cm 2cm」という値は、画像の左上と、ボックスのパディング領域の左から2cm上から2cmの点を揃えます。
  「0% 0%」=「top left」=「left top」
  「50% 0%」=「top」=「top center」=「center top」
  「100% 0%」=「right top」=「top right」
  「0% 50%」=「left」=「left center」=「center left」         (ie8- -ff3 -o9 -sf4 -gc2未対応)
  「50% 50%」=「center」=「center center」                    (ie8- -ff3 -o9 -sf4 -gc2未対応)
  「100% 50%」=「right」=「right center」=「center right」    (ie8- -ff3 -o9 -sf4 -gc2未対応)
  「0% 100%」=「bottom left」=「left bottom」                 (ie8- -ff3 -o9 -sf4 -gc2未対応)
  「50% 100%」=「bottom」=「bottom center」=「center bottom」 (ie8- -ff3 -o9 -sf4 -gc2未対応)
  「100% 100%」=「bottom right」=「right bottom」             (ie8- -ff3 -o9 -sf4 -gc2未対応)
  CSS2.1の仕様書におけるキーワードと長さや%値との組み合わせ   (ie8- -ff3 -o9 -sf4 -gc2未対応)
 

表示位置のキーワード

「0% 0%」=「top left」=「left top」
「50% 0%」=「top」=「top center」=「center top」
「100% 0%」=「right top」=「top right」
「0% 50%」=「left」=「left center」=「center left」         (ie8- -ff3 -o9 -sf4 -gc2未対応)
「50% 50%」=「center」=「center center」                    (ie8- -ff3 -o9 -sf4 -gc2未対応)
「100% 50%」=「right」=「right center」=「center right」    (ie8- -ff3 -o9 -sf4 -gc2未対応)
「0% 100%」=「bottom left」=「left bottom」                 (ie8- -ff3 -o9 -sf4 -gc2未対応)
「50% 100%」=「bottom」=「bottom center」=「center bottom」 (ie8- -ff3 -o9 -sf4 -gc2未対応)
「100% 100%」=「bottom right」=「right bottom」             (ie8- -ff3 -o9 -sf4 -gc2未対応)
長さや%値が1つだけ与えられた場合、その値は水平方向の配置に適用され、垂直方向の値は「50%」になります。長さや%値が2つ与えられた場合、1つ目の値が水平方向、2つ目の値が垂直方向の値になります。また、長さと%値の組み合わせ(「50% 2cm」)や負の値も使用可能です。ただし、キーワードを、長さや%値と組み合わせることはできません。指定可能なキーワードの組み合わせは上の欄に示したもののみになります。

*1 CSS2.1においてbackground-positionプロパティにおいて、「キーワードを、長さや%値と組み合わせることはできません」という記述が削除されました。つまり、「top 25%」という記述も許可されます(ie8- -ff3 -o9 -sf4 -gc2未対応)。
 
トップページ CSS2 Note ページトップ
 2005/09/21発行 2009/09/01更新