Propriedade CSS background-attachment
Exemplo
Uma imagem de fundo que não rola com a página (fixa):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Mais exemplos de "Experimente você mesmo" abaixo.
Definição e uso
A background-attachment
propriedade define se uma imagem de plano de fundo rola com o restante da página ou é fixa.
Valor padrão: | rolagem |
---|---|
Herdado: | não |
Animavel: | não. Leia sobre animáveis |
Versão: | CSS1 |
Sintaxe JavaScript: | objeto .style.backgroundAttachment="fixed" |
Suporte ao navegador
Os números na tabela especificam a primeira versão do navegador que oferece suporte total à propriedade.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Sintaxe CSS
background-attachment: scroll|fixed|local|initial|inherit;
Valores de propriedade
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 |
Mais exemplos
Exemplo
Uma imagem de fundo que irá rolar com a página (scroll). Este é o padrão:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Exemplo
Como criar um efeito de rolagem de paralaxe simples (crie uma ilusão de profundidade 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;
}
Páginas relacionadas
Tutorial de CSS: Fundo de CSS
Referência HTML DOM: propriedade backgroundAttachment