La propriété background
est une propriété raccourcie qui permet de définir les différentes valeurs des propriétés liées à la gestion des arrière-plans d'un élément. Elle permet de définir une ou plusieurs valeurs pour : {{cssxref("background-clip")}}, {{cssxref("background-color")}}, {{cssxref("background-image")}}, {{cssxref("background-origin")}}, {{cssxref("background-position")}}, {{cssxref("background-repeat")}}, {{cssxref("background-size")}}, et {{cssxref("background-attachment")}}.
Lorsqu'on utilise la propriété raccourcie background
, les valeurs fournies sont appliquées et pour les valeurs absentes, la propriété réinitialisera les propriétés détaillées avec leurs valeurs initiales.
{{cssinfo}}
Syntaxe
/* On utilise une couleur <background-color> */ background: green; /* Ici, une <bg-image> avec <repeat-style> */ background: url("test.jpg") repeat-y; /* Là <box> et <background-color> */ background: border-box red; /* Ici on utilise une seule image, centrée */ /* et remise à l'échelle */ background: no-repeat center/80% url("../img/image.png");
Valeurs
Une ou plusieurs valeurs suivantes, dans n'importe quel ordre :
<attachment>
- Voir {{cssxref("background-attachment")}}
<box>
- Voir {{cssxref("background-clip")}}
<background-color>
- Voir {{cssxref("background-color")}}
<bg-image>
- Voir {{Cssxref("background-image")}}
<position>
- Voir {{cssxref("background-position")}}
<repeat-style>
- Voir {{cssxref("background-repeat")}}
<bg-size>
- Voir {{cssxref("background-size")}}. Cette propriété doit être définie après <position>, séparée de cette dernière par une barre oblique '/'.
Syntaxe formelle
{{csssyntax}}
Exemples
HTML
<p class="banniere"> Dessine-moi une étoile<br/> Qui brille<br/> Dans le ciel. </p> <p class="attention">Voici un paragraphe !<p>
CSS
.attention { background: red; } .banniere { background: url("https://mdn.mozillademos.org/files/11983/starsolid.gif") #00D repeat-y fixed; }
Résultat
{{EmbedLiveSample("Exemples")}}
Spécifications
Spécification | État | Commentaires |
---|---|---|
{{SpecName('CSS3 Backgrounds', '#the-background', 'background')}} | {{Spec2('CSS3 Backgrounds')}} | La propriété raccourcie a été étendue pour gérer plusieurs arrière-plans et également gérer les propriétés {{cssxref("background-size")}}, {{cssxref("background-origin")}} et {{cssxref("background-clip")}}. |
{{SpecName('CSS2.1', 'colors.html#propdef-background', 'background')}} | {{Spec2('CSS2.1')}} | Pas de modification significative. |
{{SpecName('CSS1', '#background', 'background')}} | {{Spec2('CSS1')}} | Définition initiale. |
Compatibilité des navigateurs
{{CompatibilityTable}}
Fonctionnalité | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Support simple | {{CompatGeckoDesktop("1.0")}} | 1.0 | 4.0 | 3.5 | 1.0 |
Gestion de plusieurs arrière-plans | {{CompatGeckoDesktop("1.9.2")}} | 1.0 | 9.0 | 10.5 | 1.3 |
Gestion des images SVG comme arrière-plan | {{CompatGeckoDesktop("2.0")}} | 31.0 | 9.0 | 21.0 | 5.1 |
Prise en charge de {{cssxref("background-size")}} | {{CompatGeckoDesktop("18.0")}} | 21.0 | 9.0 | 21.0 | 6.1 |
Prise en charge de {{cssxref("background-origin")}} et {{cssxref("background-clip")}} | {{CompatGeckoDesktop("22.0")}} | 31.0 | 9.0 | 21.0 | 5.1 |
Fonctionnalité | Firefox Mobile (Gecko) | Android | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Support simple | {{CompatGeckoMobile("1.9.2")}} | 2.1 | 10.0 | 5.0 | 3.2 |
Gestion de plusieurs arrière-plans | {{CompatGeckoMobile("1.9.2")}} | 2.1 | 10.0 | 5.0 | 3.2 |
Gestion des images SVG comme arrière-plan | {{CompatGeckoMobile("2.0")}} | 3.0 | 10.0 | {{CompatUnknown}} | 4.2 |
Prise en charge de {{cssxref("background-size")}} | {{CompatGeckoMobile("18.0")}} | 3.0 | 10.0 | {{CompatVersionUnknown}} | 4.0 |
Prise en charge de {{cssxref("background-origin")}} et {{cssxref("background-clip")}} | {{CompatGeckoMOBILE("22.0")}} | 3.0 | 10.0 | {{CompatNo}} | 4.0 |
{{EmbedCompatTable("web-css-background")}}
Voir aussi
- {{cssxref("-moz-background-inline-policy")}}
- Les gradients
- Gérer plusieurs arrière-plans