目录

style backgroundSize 属性

示例

指定背景图片的大小:

document.getElementById("myDIV").style.backgroundSize = "60px 120px";
亲自试一试 »

描述

backgroundSize 属性设置或返回背景图片的大小。

也可以看看:

HTML 样式:背景属性

CSS 教程:CSS 背景

CSS3 教程:CSS3 背景

CSS 参考:背景大小属性


语法

返回背景大小属性:

object.style.backgroundSize

设置背景大小属性:

object.style.backgroundSize = "auto| length|cover|contain|intial|inherit"

属性值

Value Description
auto Default value. The background-image contains its width and height
length Sets the width and height of the background image. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto"
percentage Sets the width and height of the background image in percent of the parent element. The first value sets the width, the second value sets the height. If only one value is given, the second is set to "auto"
cover Scale the background image to be as large as possible so that the background area is completely covered by the background image. Some parts of the background image may not be in view within the background positioning area
contain Scale the image to the largest size such that both its width and its height can fit inside the content area
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

技术细节

默认值: 汽车
返回值: 一个字符串,表示元素的背景大小属性
CSS版本 CSS3

浏览器支持

backgroundSize是 CSS3 (1999) 的一项功能。

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

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