Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

background-attachment

Esta tradução está incompleta. Ajude atraduzir este artigo.

Resumo

Se um background-image é especificado, a propriedade CSS background-attachment determina se aquela posição da imagem é fixa com o viewport, ou se irá rolar juntamente com o seu bloco.

Initial valuescroll
Aplica-se aall elements. It also applies to ::first-letter and ::first-line.
Inheritednão
Midiavisual
Computed valueas specified
Animatablenão
Canonical orderthe unique non-ambiguous order defined by the formal grammar

Sintaxe

background-attachment: scroll;
background-attachment: fixed;
background-attachment: local;

background-attachment: inherit;

Valores

fixed
Essa chave significa que o background é fixo em relação ao viewport. Mesmo que um elemento tenha um mecanismo de rolar, o  background ‘fixed’ não movimenta com o elemento.
local
Essa chave significa que o background é fixo em relação ao conteúdo do elemento: ise ele tem um mecanismo de rolar, o background rola com o conteúdo do elemento, e a área pintada e o posicionamento do background são relativos à área de rolagem do elemento ao invés da borda de fronteira deles.
scroll
Essa chave significa que o background é fixo em relação ao elemento em si e não rola com seu conteúdo. (É efetivamente ligado à borda do elemento.)

Formal syntax

<attachment>#

where
<attachment> = scroll | fixed | local

Exemplos

Exemplo simpes

CSS

p {
  background-image: url("https://mdn.mozillademos.org/files/12057/starsolid.gif");
  background-attachment: fixed;
}

HTML

<p>
  There were doors all round the hall, but they were all locked; and when
  Alice had been all the way down one side and up the other, trying every
  door, she walked sadly down the middle, wondering how she was ever to
  get out again.
</p>

Resultado

Suporte de múltiplas imagem de background

Essa propriedade suporta múltiplas imagens de background. Você pode especificar <attachment> para cada background, separado por vírgulas. Cada imagem é combinada com o correspondente tipo de anexo, do primeiro especificado ao último.

CSS

p {
  background-image: url("https://mdn.mozillademos.org/files/12057/starsolid.gif"), url("https://mdn.mozillademos.org/files/12059/startransparent.gif");
  background-attachment: fixed, scroll;
  background-repeat: no-repeat, repeat-y;
}

HTML

<p>
  There were doors all round the hall, but they were all locked; and when
  Alice had been all the way down one side and up the other, trying every
  door, she walked sadly down the middle, wondering how she was ever to
  get out again.

  Suddenly she came upon a little three-legged table, all made of solid
  glass; there was nothing on it except a tiny golden key, and Alice's
  first thought was that it might belong to one of the doors of the hall;
  but, alas! either the locks were too large, or the key was too small,
  but at any rate it would not open any of them. However, on the second
  time round, she came upon a low curtain she had not noticed before, and
  behind it was a little door about fifteen inches high: she tried the
  little golden key in the lock, and to her great delight it fitted!
</p>

Resultado

Especificações

Especificação Status Comentário
CSS Backgrounds and Borders Module Level 3
The definition of 'background-attachment' in that specification.
Candidate Recommendation The shorthand property has been extended to support multiple backgrounds and the local value.
CSS Level 2 (Revision 1)
The definition of 'background-attachment' in that specification.
Recommendation Mudança não significativa.
CSS Level 1
The definition of 'background-attachment' in that specification.
Recommendation Mudança não significativa

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) 4.0 3.5 1.0
Multiple backgrounds 1.0 3.6 (1.9.2) 9.0 10.5 1.3
local 4.0 25 (25) 9.0 10.5 5.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 2.1 1.0 (1.9.2) ? 10.0 3.2
Multiple backgrounds 2.1 1.0 (1.9.2) ? 10.0 3.2
local ? 25.0 (25) ? ? ?

Veja também

Etiquetas do documento e colaboradores

 Colaboradores desta página: alexfqc
 Última atualização por: alexfqc,