CSS背景-添付ファイルプロパティ
例
ページとともにスクロールしない背景画像(修正済み):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
このbackground-attachment
プロパティは、背景画像をページの残りの部分と一緒にスクロールするか、固定するかを設定します。
デフォルト値: | スクロール |
---|---|
遺伝性の: | いいえ |
アニメート可能: | 番号。アニメート可能について読む |
バージョン: | CSS1 |
JavaScript構文: | object .style.backgroundAttachment = "fixed" |
ブラウザのサポート
表の数字は、プロパティを完全にサポートする最初のブラウザバージョンを示しています。
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
CSS構文
background-attachment: scroll|fixed|local|initial|inherit;
プロパティ値
Value | Description |
---|---|
scroll | The background image will scroll with the page. This is default |
fixed | The background image will not scroll with the page |
local | The background image will scroll with the element's contents |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
その他の例
例
ページとともにスクロールする背景画像(スクロール)。これはデフォルトです:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
例
単純な視差スクロール効果を作成する方法(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;
}
関連ページ
CSSチュートリアル:CSSの背景
HTML DOMリファレンス: backgroundAttachmentプロパティ