--- title: background-attachment slug: Web/CSS/background-attachment translation_of: Web/CSS/background-attachment ---
Se um {{cssxref("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.
{{cssinfo}}
background-attachment: scroll; background-attachment: fixed; background-attachment: local; background-attachment: inherit;
fixed
local
scroll
p { background-image: url("https://mdn.mozillademos.org/files/12057/starsolid.gif"); background-attachment: fixed; }
<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>
{{EmbedLiveSample("Simple_example")}}
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.
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; }
<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>
{{EmbedLiveSample("Multiple_background_image_support")}}
Especificação | Status | Comentário |
---|---|---|
{{SpecName('CSS3 Backgrounds', '#the-background-attachment', 'background-attachment')}} | {{Spec2('CSS3 Backgrounds')}} | The shorthand property has been extended to support multiple backgrounds and the local value. |
{{SpecName('CSS2.1', 'colors.html#propdef-background-attachment', 'background-attachment')}} | {{Spec2('CSS2.1')}} | Mudança não significativa. |
{{SpecName('CSS1', '#background-attachment', 'background-attachment')}} | {{Spec2('CSS1')}} | Mudança não significativa |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoDesktop("1.0")}} | 4.0 | 3.5 | 1.0 |
Multiple backgrounds | 1.0 | {{CompatGeckoDesktop("1.9.2")}} | 9.0 | 10.5 | 1.3 |
local |
4.0 | {{CompatGeckoDesktop("25")}} | 9.0 | 10.5 | 5.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 2.1 | {{CompatGeckoMobile("1.9.2")}} | {{CompatUnknown}} | 10.0 | 3.2 |
Multiple backgrounds | 2.1 | {{CompatGeckoMobile("1.9.2")}} | {{CompatUnknown}} | 10.0 | 3.2 |
local |
{{CompatUnknown}} | {{CompatGeckoMobile("25")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |