Fondo de estiloPosición Propiedad
Ejemplo
Cambiar la posición de una imagen de fondo:
document.body.style.backgroundPosition = "top right";
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
La propiedad backgroundPosition establece o devuelve la posición de una imagen de fondo dentro de un elemento.
Compatibilidad con navegador
Los números de la tabla especifican la primera versión del navegador que es totalmente compatible con la propiedad.
Property | |||||
---|---|---|---|---|---|
backgroundPosition | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Sintaxis
Devuelve la propiedad backgroundPosition:
object.style.backgroundPosition
Establezca la propiedad backgroundPosition:
object.style.backgroundPosition = value
Valores de propiedad
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 |
Detalles técnicos
Valor por defecto: | 0% 0% |
---|---|
Valor de retorno: | Una cadena, que representa la posición de una imagen de fondo |
Versión CSS | CSS1 |
Más ejemplos
Ejemplo
Cambie la posición de la imagen de fondo en un elemento <div> al centro de la parte inferior:
document.getElementById("myDiv").style.backgroundPosition = "center bottom";
Ejemplo
Cambie la posición de la imagen de fondo en un elemento <div> a 200 px en horizontal y 40 px en vertical:
document.getElementById("myDiv").style.backgroundPosition = "200px 40px";
Ejemplo
Devuelve la posición de la imagen de fondo en un elemento <div>:
document.getElementById("myDiv").style.backgroundPosition;
páginas relacionadas
Tutorial CSS: Fondo CSS
Referencia CSS: propiedad de imagen de fondo
Referencia de CSS: propiedad de posición de fondo
Referencia HTML DOM: propiedad de fondo