Styl backgroundPosition Vlastnost
Příklad
Změňte polohu obrázku na pozadí:
document.body.style.backgroundPosition = "top right";
Další příklady „Vyzkoušejte si to sami“ níže.
Definice a použití
Vlastnost backgroundPosition nastavuje nebo vrací polohu obrázku pozadí v rámci prvku.
Podpora prohlížeče
Čísla v tabulce určují první verzi prohlížeče, která plně podporuje vlastnost.
Property | |||||
---|---|---|---|---|---|
backgroundPosition | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Syntax
Vraťte vlastnost backgroundPosition:
object.style.backgroundPosition
Nastavte vlastnost backgroundPosition:
object.style.backgroundPosition = value
Hodnoty vlastností
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 |
Technické údaje
Výchozí hodnota: | 0 % 0 % |
---|---|
Návratová hodnota: | Řetězec představující pozici obrázku na pozadí |
Verze CSS | CSS1 |
Další příklady
Příklad
Změňte polohu obrázku na pozadí v prvku <div> na střed dole:
document.getElementById("myDiv").style.backgroundPosition = "center bottom";
Příklad
Změňte polohu obrázku na pozadí v prvku <div> na 200 pixelů vodorovně a 40 pixelů svisle:
document.getElementById("myDiv").style.backgroundPosition = "200px 40px";
Příklad
Vraťte polohu obrázku na pozadí v prvku <div>:
document.getElementById("myDiv").style.backgroundPosition;
Související stránky
CSS tutoriál: CSS Background
CSS reference: vlastnost background-image
CSS reference: vlastnost background-position
HTML DOM reference: vlastnost pozadí