目录

style backgroundRepeat 属性

示例

将背景图片设置为不重复:

document.body.style.backgroundRepeat = "repeat-y";
亲自试一试 »

下面有更多 "亲自试一试" 示例。


描述

backgroundRepeat 属性设置或返回如何重复(平铺)背景图片。

也可以看看:

HTML 样式:背景属性

CSS 教程:CSS 背景

CSS3 教程:CSS3 背景

CSS 参考:背景重复属性


语法

返回backgroundRepeat属性:

object.style.backgroundRepeat

设置backgroundRepeat属性:

object.style.backgroundRepeat = "repeat|repeat-x|repeat-y|no-repeat|initial|inherit"

属性值

Value Description
repeat The background image is repeated both vertically and horizontally. This is default
repeat-x The background image is only repeated horizontally
repeat-y The background image is only repeated vertically
no-repeat The background-image is not repeated
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

技术细节

默认值: 重复
返回值: 一个字符串,表示背景图片如何重复
CSS版本 CSS1


浏览器支持

backgroundRepeat是 CSS1 (1996) 的一项功能。

所有浏览器都完全支持它:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

更多示例

示例

更改指定 DIV 元素的 backgroundRepeat 属性:

document.getElementById("myDIV").style.backgroundRepeat = "repeat-x";
亲自试一试 »

示例

设置背景图片水平或垂直重复:

function repeatVer() {
  document.body.style.backgroundRepeat = "repeat-y";
}

function repeatHor() {
  document.body.style.backgroundRepeat = "repeat-x";
}
亲自试一试 »

示例

返回文档的背景重复值:

alert(document.body.style.backgroundRepeat);
亲自试一试 »