Thuộc tính tệp đính kèm nền CSS
Thí dụ
Hình nền sẽ không cuộn theo trang (đã sửa):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Thêm các ví dụ "Hãy tự mình thử" bên dưới.
Định nghĩa và Cách sử dụng
Thuộc background-attachment
tính đặt xem hình nền cuộn với phần còn lại của trang hay được cố định.
Giá trị mặc định: | cuộn giấy |
---|---|
Thừa hưởng: | không |
Hoạt hình: | không. Đọc về hoạt hình |
Phiên bản: | CSS1 |
Cú pháp JavaScript: | object .style.backgroundAttachment = "fixed" |
Hỗ trợ trình duyệt
Các số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ đầy đủ thuộc tính.
Property | |||||
---|---|---|---|---|---|
background-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Cú pháp CSS
background-attachment: scroll|fixed|local|initial|inherit;
Giá trị tài sản
Value | Description |
---|---|
scroll | The background image will scroll with the page. This is default |
fixed | The background image will not scroll with the page |
local | The background image will scroll with the element's contents |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Các ví dụ khác
Thí dụ
Hình nền sẽ cuộn cùng trang (cuộn). Đây là mặc định:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Thí dụ
Cách tạo hiệu ứng cuộn thị sai đơn giản (tạo ảo giác về chiều sâu 3D):
.fixed-bg {
/* The background image */
background-image: url("img_tree.gif");
/* Set a specified height, or the minimum height for the background image */
min-height: 500px;
/* Set background image to fixed (don't scroll along with the page) */
background-attachment: fixed;
/* Center the background image */
background-position: center;
/* Set the background image to no repeat */
background-repeat: no-repeat;
/* Scale the background image to be as large as possible */
background-size: cover;
}
Các trang liên quan
Hướng dẫn CSS: Nền CSS
Tham chiếu DOM HTML: thuộc tính backgroundAttachment