background-attachment

<< Guida di riferimento ai CSS

Sommario

Se è stata specificata una background-image, la proprietà background-attachment determina se l'immagine è fissa o può scorrere all'interno dell'elemento al quale è assegnata.

  • Valore iniziale: scroll
  • Si applica a: tutti gli elementi
  • Eredità: no
  • valori percentuali: non applicabile
  • Media: visual
  • Valore calcolato: come specificato

Sintassi

background-attachment: scroll | fixed | inherit

Valori

scroll 
Se scroll viene specificato, l'immagine di sfondo può scorrere all'interno dell'elemento al quale è assegnata
fixed 
Se fixed viene specificato, l'immagine di sfondo è fissa nell'elemento che la contiene

Esempi

Simple example

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>

Result

Multiple background image support

This property supports multiple background images. You can specify a different <attachment> for each background, separated by commas. Each image is matched with the corresponding attachment type, from first specified to last.

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>

Result

Specifiche

Compatibilità con i browser

Browser Versione minima
Internet Explorer 4
Firefox 1
Netscape 6
Opera 3.5

Si veda anche

background, background-color, background-image, background-position, background-repeat

 

Tag del documento e collaboratori

 Hanno collaborato alla realizzazione di questa pagina: SphinxKnight, teoli, Federico
 Ultima modifica di: SphinxKnight,