背景画像の位置決め。
名前 | background-position
|
---|---|
値 | <bg-position># |
初期値 | 0% 0% |
対象 | 全ての要素 |
継承 | されない |
百分率 | 背景位置決め区画のサイズから 背景画像のサイズを引いた結果に相対的 ─ テキストを見よ。 |
算出値 | リスト:各アイテムは、左上原点からの[横、縦]オフセットからなる ─ 各オフセットは、算出された <length-percentage> |
アニメーション型 | 離散的 |
このプロパティは、何枚かの背景画像が指定されている下で、各 画像の,対応する背景位置決め区画における(リサイズ後の)初期位置を指定する。
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:top; ">あ</DIV>
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:top center; ">あ</DIV>
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:top 30% left 80%; ">あ</DIV>
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg), url(Com/BG2.jpg); background-repeat:no-repeat; background-position:top left, bottom right; ">あ</DIV>
注記: キーワードによるペアは順不同である一方、キーワードと[長さ/百分率]の組み合せでは,順序は入れ替えられない。したがって、center left は妥当であるが、50% left は無効になる。
例えば background-position: bottom 10px right 20px は、[ 下辺から上へ 10px, 右辺から左へ 20px ]オフセットされた所を表現する。
値が 3 個の場合の欠落しているオフセットは、 0 と見做される。
[正な値/負な値]は、背景位置決め区画の辺から[内方/外方]へのオフセットを表現する。
top
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:top; ">あ</DIV>
<DIV style="border:10px dotted green; width:80px; height:80px; padding:10px; background-image:url(Com/BG1.jpg); background-position:top; ">あ</DIV>
right
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:right; ">あ</DIV>
<DIV style="border:10px dotted green; width:80px; height:80px; padding:10px; background-image:url(Com/BG1.jpg); background-position:right; ">あ</DIV>
bottom
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:bottom; ">あ</DIV>
left
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:left; ">あ</DIV>
center
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:center; ">あ</DIV>
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:30% 50%; ">あ</DIV>
例えば、値ペア 0% 0% に対しては、画像の左上隅が、通例的には(background-origin を特に指定しない限り)ボックスのパディング辺による区画の左上隅に揃えられる。
値ペア 100% 100% に対しては、画像の右下隅が、区画の右下隅に揃えられる。
値ペア 75% 50% に対しては、画像の左上隅から[75% 右、50% 下]の地点が、区画の左上隅から[75% 右、50% 下]の地点に揃えられる(下図)。
<DIV style="border:1px solid red; width:100px; height:100px; padding:10px; background-image:url(Com/BG1.jpg); background-repeat:no-repeat; background-position:30% 50%; ">あ</DIV>
次の宣言は、左上隅からの[横、縦]オフセットを明示的に与える:
background-position: left 10px top 15px; /* 10px, 15px */ background-position: left top ; /* 0px, 0px */ background-position: 10px 15px; /* 10px, 15px */ background-position: left 15px; /* 0px, 15px */ background-position: 10px top ; /* 10px, 0px */ background-position: left top 15px; /* 0px, 15px */ background-position: left 10px top ; /* 10px, 0px */
背景位置を、左上でない隅から相対的にすることもできる。例えば、次のものは、背景画像を[下端から 10px、右端から 3em ]の所に置く。
background-position: bottom 10px right 3em;
表示内容: |
表示内容: |