Phong cách nềnKích thước thuộc tính
Ví dụ
Chỉ định kích thước của hình nền:
document.getElementById("myDIV").style.backgroundSize = "60px 120px";
Hãy tự mình thử »Sự miêu tả
Thuộc tính BackgroundSize đặt hoặc trả về kích thước của hình nền.
Xem thêm:
Kiểu HTML: Thuộc tính nền
Hướng dẫn CSS: Nền CSS
Hướng dẫn CSS3: Nền CSS3
Tham khảo CSS: Thuộc tính kích thước nền
Cú pháp
Trả về thuộc tính BackgroundSize:
object .style.backgroundSize
Đặt thuộc tính BackgroundSize:
object .style.backgroundSize = "auto| length |cover|contain|intial|inherit"
Giá trị tài sản
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 |
Chi tiết kỹ thuật
Giá trị mặc định: | tự động |
---|---|
Giá trị trả về: | Một Chuỗi, biểu thị thuộc tính kích thước nền của một phần tử |
Phiên bản CSS | CSS3 |
Hỗ trợ trình duyệt
backgroundSize
là một tính năng CSS3 (1999).
Nó được hỗ trợ đầy đủ trong tất cả các trình duyệt:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |