Viết tắt nền CSS
Nền CSS - Thuộc tính viết tắt
Để rút ngắn mã, cũng có thể chỉ định tất cả các thuộc tính nền trong một thuộc tính duy nhất. Đây được gọi là thuộc tính tốc ký.
Thay vì viết:
body {
background-color: #ffffff;
background-image:
url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
Bạn có thể sử dụng thuộc tính tốc ký background
:
Ví dụ
Sử dụng thuộc tính tốc ký để đặt thuộc tính nền trong một khai báo:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
Hãy tự mình thử »Khi sử dụng thuộc tính tốc ký, thứ tự của các giá trị thuộc tính là:
-
background-color
-
background-image
-
background-repeat
-
background-attachment
-
background-position
Sẽ không có vấn đề gì nếu thiếu một trong các giá trị thuộc tính, miễn là các giá trị khác theo thứ tự này. Lưu ý rằng chúng tôi không sử dụng thuộc tính đính kèm nền trong các ví dụ trên vì nó không có giá trị.
Tất cả thuộc tính nền CSS
Property | Description |
---|---|
background | Sets all the background properties in one declaration |
background-attachment | Sets whether a background image is fixed or scrolls with the rest of the page |
background-clip | Specifies the painting area of the background |
background-color | Sets the background color of an element |
background-image | Sets the background image for an element |
background-origin | Specifies where the background image(s) is/are positioned |
background-position | Sets the starting position of a background image |
background-repeat | Sets how a background image will be repeated |
background-size | Specifies the size of the background image(s) |