HTML DOM propiedad Estilo BackgroundImage
Objetos de estilo
Definición y Uso
BackgroundImage conjuntos de propiedades o devuelve los elementos de imagen de fondo.
gramática
Configuración de las propiedades BackgroundImage:
Object.style.backgroundImage="url('URL')|none|inherit"
BackgroundImage propiedades para la espalda:
Object.style.backgroundImage
值 | 描述 |
---|---|
url('URL') | 图像文件的位置。 |
none | 默认。没有背景图像。 |
inherit | background-image 属性的设置从父元素继承。 |
Soporte para el navegador
Todos los principales navegadores soportan la propiedad BackgroundImage.
Nota: Internet Explorer 7 y versiones anteriores no son compatibles con el valor "heredar".IE8 sólo proporciona! DOCTYPE apoyado "hereda". apoyo IE9 "hereda".
Notas y sugerencias
Consejo: Además de la imagen de fondo, también debe especificar un color de fondo.Si la imagen no está disponible, vamos a utilizar el color de fondo.
Ejemplos
Ejemplos
Imagen de fondo:
<! DOCTYPE html>
<Html>
<Head>
<Charset Meta = "UTF-8">
<Title> Este tutorial (w3big.com) </ title>
<Script>
displayResult función () {
document.body.style.backgroundColor = "# f3f3f3";
document.body.style.backgroundImage = "url ( 'img_tree.png')";
}
</ Script>
</ Head>
<Cuerpo>
<H1> Hello World! </ H1>
<br>
<Botón type = "button" onclick = "displayResult ()"> establecer la imagen de fondo </ botón>
</ Body>
</ Html>
<Html>
<Head>
<Charset Meta = "UTF-8">
<Title> Este tutorial (w3big.com) </ title>
<Script>
displayResult función () {
document.body.style.backgroundColor = "# f3f3f3";
document.body.style.backgroundImage = "url ( 'img_tree.png')";
}
</ Script>
</ Head>
<Cuerpo>
<H1> Hello World! </ H1>
<br>
<Botón type = "button" onclick = "displayResult ()"> establecer la imagen de fondo </ botón>
</ Body>
</ Html>
Trate »
Objetos de estilo