Latest web development tutorials

propriedade HTML DOM Estilo backgroundPosition

Estilo Object Reference estilo Objects

Definição e Uso

backgroundPosition conjuntos de propriedades ou retorna a posição dos elementos de imagem de fundo.

gramática

Definindo as propriedades backgroundPosition:

Object.style.backgroundPosition="position"

Propriedades backgroundPosition Voltar:

Object.style.backgroundPosition

Dica: O valor padrão da propriedade é 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 背景位置属性的设置从父元素继承。


Suporte a navegadores

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Todos os principais navegadores suportam backgroundPosition propriedade.

Nota: IE7 e versões anteriores não suportam o valor "herdar".IE8 só fornece! DOCTYPE suportado "herdar". suporte IE9 "herdar".


Exemplos

Exemplos

Alterar a imagem de fundo aqui:

<! DOCTYPE html>
<Html>
<Head>
<Charset Meta = "utf-8">
<Title> Este tutorial (w3big.com) </ title>
<Style>
div {
background-image: url ( 'img_tree.png');
background-repeat: no-repeat;
width: 400px;
height: 400px;
border: 1px solid # 000000;
}
</ Style>
<Script>
displayResult function () {
. Document.getElementById ( "div1") style.backgroundPosition = "bottom center";
}
</ Script>
</ Head>
<Body>

<Button type = "button" onclick = "displayResult ()"> para modificar a posição da imagem de fundo </ button>
<br>
<Div id = "div1">
</ Div>

</ Body>
</ Html>

tente »


Estilo Object Reference estilo Objects