CSS background-position-y 属性
- 前のページ background-position-x
- 次のページ background-repeat
定義と用法
background-position-y
属性は、背景画像のy軸上の位置を設定するために使用されます。
ヒント:デフォルトでは、背景画像は要素の左上隅に配置され、垂直および水平方向に繰り返されます。
実例
例 1
y軸上で背景画像を配置する方法は:
div { background-image: url('w3css.gif'); background-repeat: no-repeat; background-position-y: center; }
例 2
背景画像をトップに配置する方法は:
body { background-image: url('w3css.gif'); background-repeat: no-repeat; background-attachment: fixed; background-position-y: bottom; }
例3
パーセントを使用してy軸上で背景画像を定位する方法:
body { background-image: url('w3css.gif'); background-repeat: no-repeat; background-attachment: fixed; background-position-y: 50%; }
例4
ピクセルを使用してy軸上で背景画像を定位する方法:
body { background-image: url('w3css.gif'); background-repeat: no-repeat; background-attachment: fixed; background-position-y: 80px; }
CSS 语法
background-position-y: value;
属性値
値 | 説明 |
---|---|
top | 背景定位をy軸のトップに設定します。 |
bottom | 背景定位をy軸のボトムに設定します。 |
center | 背景定位をy軸の中心に設定します。 |
y% |
y軸のトップは0%、ボトムは100%です。 百分比值は、背景定位エリアの高さから背景画像の高さを引いたものです。 |
ypos |
トップからの垂直距離です。 単位はピクセル(例:0px)などができます CSS 単位。 |
ypos offset |
二値構文、FirefoxとSafariでのみサポートされています。
単位はピクセル(例:0px)などができます CSS 単位。 |
initial | この属性をデフォルト値に設定します。参照してください: initial。 |
inherit | この属性を親要素から継承します。参照してください: inherit。 |
技術的詳細
デフォルト値: | 0% |
---|---|
継承性: | いいえ |
アニメーション作成: | サポート。参照してください:アニメーション関連属性。 |
バージョン: | CSS3 |
JavaScript 语法: | object.style.backgroundPositionY="center" |
ブラウザのサポート
テーブルの数字は、この属性を完全にサポートする最初のブラウザのバージョンを示しています。
Chrome | Edge | Firefox | Safari | Opera | |
---|---|---|---|---|---|
単値構文 | 1.0 | 12.0 | 49.0 | 1.0 | 15.0 |
二値構文 | サポート外 | サポート外 | 49.0 | 15.4 | サポート外 |
関連ページ
チュートリアル:CSS 背景
CSS リファレンス:background-image 属性
CSS リファレンス:background-position 属性
CSS リファレンス:background-position-x 属性
HTML DOM リファレンス:backgroundPosition 属性
- 前のページ background-position-x
- 次のページ background-repeat