Latest web development tutorials

HTML DOM style propriétés de fond

Style de Object Reference style Objets

Définition et utilisation

fond propriété raccourcie pour définir ou retourner jusqu'à cinq propriétés de fond séparées.

Avec cette propriété, vous pouvez définir / retour:

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position

Les propriétés ci-dessus peuvent être fournis attributs de style séparés. recommande fortement d'utiliser un attribut séparé une telle meilleure contrôlabilité.

grammaire

Définissez les propriétés d'arrière-plan:

Object.style.background="color image repeat attachment position"

Retour arrière-plan propriétés:

Object.style.background

Astuce: La valeur par défaut de la propriété est l'arrière - plan: aucun transparent repeat scroll 0% 0 %.

参数 描述
color 设置一个元素的背景颜色
image 设置一个元素的背景图像
repeat 设置如何重复背景图像
attachment 设置背景图像是否固定或者随着页面的其余部分滚动
position 设置背景图像的起始位置


support du navigateur

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Tous les principaux navigateurs prennent en charge les attributs de fond.


Exemples

Exemples

Définir le document de fond style:

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Titre> Ce tutoriel (w3big.com) </ title>
<Script>
fonction displayResult () {
document.body.style.background = "F3F3F3 url # ( 'de img_tree.png') sans répéter en haut à droite";
}
</ Script>
</ Head>
<Body>

<H1> Bonjour tout le monde! </ H1>
<br>
<Bouton type = "button" onclick = "displayResult ()"> définir le fond </ button>

</ Body>
</ Html>

Essayez »


Style de Object Reference style Objets