CSS background-attachment プロパティ

❮ 前章へ 完全な CSS リファレンス 次へ ❯

固定した背景画像を指定する方法:

body {
    background-image: url('w3css.gif');
    background-repeat: no-repeat;
    background-attachment: fixed;
}
Try it Yourself ❯

他の "Try it Yourself" 例が下にあります。


定義と用法

background-attachment プロパティは、背景画像を固定するか、スクロールと共に移動するかどうかを指定します。

デフォルト値: scroll
継承: 継承する
アニメーション可否: 不可。animatable を参照
バージョン: CSS1
JavaScript 構文: object.style.backgroundAttachment="fixed" Try it

ブラウザ・サポート

表中の数字は、完全にプロパティをサポートした最初のブラウザのバージョンです。

プロパティ
background-attachment 1.0 4.0 1.0 1.0 3.5

注: Internet Explorer 8 以前のバージョンでは、一つの要素に複数の背景画像をサポートしていません。


CSS 構文

background-attachment: scroll|fixed|local|initial|inherit;

プロパティの値

説明
scroll 背景画像は要素と共にスクロールします。デフォルトです
fixed 背景をビューポートに対して固定します
local 要素のコンテンツと共に背景をスクロールします
initial プロパティにデフォルト値を設定します。initial を参照
inherit このプロパティは親要素を継承します。inherit を参照

Examples

その他の例

簡単な parallax(視差)スクロール効果をを作成する(3D深度の錯覚を作成する)方法:

.fixed-bg {
    /* The background image */
    background-image: url("img_tree.gif");
    /* Set a specified height, or the minimum height for the background image */
    min-height: 500px;
    /* Set background image to fixed (don't scroll along with the page) */
    background-attachment: fixed;
    /* Center the background image */
    background-position: center;
    /* Set the background image to no repeat */
    background-repeat: no-repeat;
    /* Scale the background image to be as large as possible */
    background-size: cover;
}
Try it Yourself ❯

関連ページ

CSS チュートリアル: CSS Background

HTML DOM リファレンス: backgroundAttachment property


❮ 前章へ 完全な CSS リファレンス 次へ ❯