HTML DOM propiedad Estilo backgroundPosition
Definición y Uso
backgroundPosition conjuntos de propiedades o devuelve la posición de los elementos de imagen de fondo.
gramática
Configuración de las propiedades backgroundPosition:
Object.style.backgroundPosition="position"
backgroundPosition propiedades para la espalda:
Object.style.backgroundPosition
Consejo: El valor predeterminado de la propiedad es backgroundPosition: 0% 0%.
值 | 描述 |
---|---|
top left top center top right center left center center center right bottom left bottom center bottom right |
如果仅指定一个关键字,其他值将是 "center"。 |
x% y% | x 值表示水平位置,y 值表示垂直位置。左上角是 0% 0%。右下角是 100% 100%。如果仅指定一个值,其他值将是 50%。 |
xpos ypos | x 值表示水平位置,y 值表示垂直位置。左上角是 0 0。单位可以是像素(0px 0px)或任何其他的 CSS 单位。如果仅指定一个值,其他值将是 50%。您可以混合使用 % 和单位。 |
inherit | 背景位置属性的设置从父元素继承。 |
Soporte para el navegador
Todos los principales navegadores soportan la propiedad backgroundPosition.
Nota: Internet Explorer 7 y versiones anteriores no son compatibles con el valor "heredar".IE8 sólo proporciona! DOCTYPE apoyado "hereda". apoyo IE9 "hereda".
Ejemplos
Ejemplos
Cambiar la imagen de fondo aquí:
<! DOCTYPE html>
<Html>
<Head>
<Charset Meta = "UTF-8">
<Title> Este tutorial (w3big.com) </ title>
<Style>
div {
Imagen de fondo: url ( 'img_tree.png');
background-repeat: no-repeat;
Anchura: 400px;
altura: 400px;
frontera: 1px solid # 000000;
}
</ Style>
<Script>
displayResult función () {
. Document.getElementById ( "div1") style.backgroundPosition = "inferior central";
}
</ Script>
</ Head>
<Cuerpo>
<Botón type = "button" onclick = "displayResult ()"> para modificar la posición de la imagen de fondo </ botón>
<br>
<Div id = "div1">
</ Div>
</ Body>
</ Html>
<Html>
<Head>
<Charset Meta = "UTF-8">
<Title> Este tutorial (w3big.com) </ title>
<Style>
div {
Imagen de fondo: url ( 'img_tree.png');
background-repeat: no-repeat;
Anchura: 400px;
altura: 400px;
frontera: 1px solid # 000000;
}
</ Style>
<Script>
displayResult función () {
. Document.getElementById ( "div1") style.backgroundPosition = "inferior central";
}
</ Script>
</ Head>
<Cuerpo>
<Botón type = "button" onclick = "displayResult ()"> para modificar la posición de la imagen de fondo </ botón>
<br>
<Div id = "div1">
</ Div>
</ Body>
</ Html>
Trate »
Objetos de estilo