Tốc ký nền CSS
Nền CSS - Thuộc tính tốc ký
Để 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 viết tắt background
:
Thí dụ
Sử dụng thuộc tính tốc ký để đặt các thuộc tính nền trong một khai báo:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
Khi sử dụng thuộc tính viết tắt, thứ tự của các giá trị thuộc tính là:
background-color
background-image
background-repeat
background-attachment
background-position
Không quan trọng nếu một trong các giá trị thuộc tính bị thiếu, 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 tệp đính kèm nền trong các ví dụ trên, vì nó không có giá trị.
Tất cả cá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) |