Properti HTML DOM Style backgroundPosition
Definisi dan Penggunaan
backgroundPosition set properti atau mengembalikan posisi dari elemen gambar latar belakang.
tatabahasa
Pengaturan properti backgroundPosition:
Object.style.backgroundPosition="position"
Kembali sifat backgroundPosition:
Object.style.backgroundPosition
Tip: Nilai default dari properti adalah 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 | 背景位置属性的设置从父元素继承。 |
Dukungan Browser
Semua browser utama mendukung properti backgroundPosition.
Catatan: IE7 dan versi sebelumnya tidak mendukung "mewarisi" nilai.IE8 hanya menyediakan! DOCTYPE didukung "mewarisi". dukungan IE9 "mewarisi".
contoh
contoh
Mengubah gambar latar belakang di sini:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Gaya>
div {
background-image: url ( 'img_tree.png');
background-repeat: no-repeat;
width: 400px;
height: 400px;
border: 1px solid # 000000;
}
</ Style>
<Script>
Fungsi displayResult () {
. Document.getElementById ( "Div1") style.backgroundPosition = "tengah bawah";
}
</ Script>
</ Kepala>
<Body>
<Tombol type = "button" onclick = "displayResult ()"> untuk mengubah posisi gambar latar belakang </ button>
Situs
<Div id = "Div1">
</ Div>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Gaya>
div {
background-image: url ( 'img_tree.png');
background-repeat: no-repeat;
width: 400px;
height: 400px;
border: 1px solid # 000000;
}
</ Style>
<Script>
Fungsi displayResult () {
. Document.getElementById ( "Div1") style.backgroundPosition = "tengah bawah";
}
</ Script>
</ Kepala>
<Body>
<Tombol type = "button" onclick = "displayResult ()"> untuk mengubah posisi gambar latar belakang </ button>
Situs
<Div id = "Div1">
</ Div>
</ Body>
</ Html>
Coba »
gaya Objects