Style backgroundPosition Property
Exemple
Changer la position d'une image d'arrière-plan :
document.body.style.backgroundPosition = "top right";
Plus d'exemples "Essayez-le vous-même" ci-dessous.
Définition et utilisation
La propriété backgroundPosition définit ou renvoie la position d'une image d'arrière-plan dans un élément.
Prise en charge du navigateur
Les nombres dans le tableau indiquent la première version du navigateur qui prend entièrement en charge la propriété.
Property | |||||
---|---|---|---|---|---|
backgroundPosition | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Syntaxe
Renvoyez la propriété backgroundPosition :
object.style.backgroundPosition
Définissez la propriété backgroundPosition :
object.style.backgroundPosition = value
Valeurs de propriété
Value | Description |
---|---|
top left top center top right center left center center center right bottom left bottom center bottom right |
If you only specify one keyword, the other value will be "center". |
x% y% | The x value indicates the horizontal position and the y value indicates the vertical position. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. |
xpos ypos | The x value indicates the horizontal position and the y value indicates the vertical position. The top left corner is 0 0. Units can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You can mix % and units |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Détails techniques
Valeur par défaut: | 0% 0% |
---|---|
Valeur de retour : | Une chaîne, représentant la position d'une image d'arrière-plan |
Version CSS | CSS1 |
Plus d'exemples
Exemple
Modifiez la position de l'image d'arrière-plan dans un élément <div> pour centrer en bas :
document.getElementById("myDiv").style.backgroundPosition = "center bottom";
Exemple
Modifiez la position de l'image d'arrière-plan dans un élément <div> à 200px horizontal et 40px vertical :
document.getElementById("myDiv").style.backgroundPosition = "200px 40px";
Exemple
Renvoie la position de l'image de fond dans un élément <div> :
document.getElementById("myDiv").style.backgroundPosition;
Pages connexes
Tutoriel CSS : Arrière-plan CSS
Référence CSS : propriété background-image
Référence CSS : propriété background-position
Référence HTML DOM : propriété background