HTML DOM Style backgroundImage property
Definition and Usage
backgroundImage property sets or returns the background image elements.
grammar
Setting backgroundImage properties:
Object.style.backgroundImage="url('URL')|none|inherit"
Back backgroundImage properties:
Object.style.backgroundImage
值 | 描述 |
---|---|
url('URL') | 图像文件的位置。 |
none | 默认。没有背景图像。 |
inherit | background-image 属性的设置从父元素继承。 |
Browser Support
All major browsers support backgroundImage property.
Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".
Tips and Notes
Tip: In addition tothe background image, you should also specify a background color. If the image is not available, we will use the background color.
Examples
Examples
Background image:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function displayResult () {
document.body.style.backgroundColor = "# f3f3f3";
document.body.style.backgroundImage = "url ( 'img_tree.png')";
}
</ Script>
</ Head>
<Body>
<H1> Hello World! </ H1>
<br>
<Button type = "button" onclick = "displayResult ()"> set the background image </ button>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function displayResult () {
document.body.style.backgroundColor = "# f3f3f3";
document.body.style.backgroundImage = "url ( 'img_tree.png')";
}
</ Script>
</ Head>
<Body>
<H1> Hello World! </ H1>
<br>
<Button type = "button" onclick = "displayResult ()"> set the background image </ button>
</ Body>
</ Html>
try it"
Style Objects