Thuộc tính nền-vị trí-y CSS
Ví dụ
Cách định vị hình nền trên trục y:
div
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-position-y: center;
}
Hãy tự mình thử »Thêm ví dụ "Hãy tự mình thử" bên dưới.
Định nghĩa và cách sử dụng
Thuộc tính background-position-y
đặt vị trí của hình nền trên trục y.
Mẹo: Theo mặc định, hình nền được đặt ở góc trên cùng bên trái của một phần tử và được lặp lại theo cả chiều dọc và chiều ngang.
Đưa ra bản chạy thử ❯Giá trị mặc định: | 0% |
---|---|
Thừa hưởng: | KHÔNG |
Hoạt hình: | Đúng. Đọc về hoạt hình Hãy thử nó |
Phiên bản: | CSS3 |
Cú pháp JavaScript: | object .style.backgroundPositionY="center" Hãy dùng thử |
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-position-y | 1.0 | 12.0 | 49.0 | 1.0 | 15.0 |
background-position-y (with two value syntax) |
Not supported | Not supported | 49.0 | 15.4 | Not supported |
Cú pháp CSS
background-position-y: value ;
Giá trị tài sản
Value | Description | Demo |
---|---|---|
top | Positions background top on y-axis. | Demo ❯ |
bottom | Positions background bottom on y-axis. | Demo ❯ |
center | Positions background center on y-axis. | Demo ❯ |
y% | Top side is 0% on y-axis, and bottom side is 100%. Percentage value refers to height of background positioning area minus height of background image. | Demo ❯ |
ypos | Vertical distance from top side. Units can be pixels (0px) or any other CSS units . | Demo ❯ |
ypos offset | Two value syntax, only supported in Firefox and Safari. - ypos is set either to "top" or "bottom". - offset is vertical distance from background image and "top" or "bottom" side set with ypos . Units can be pixels or any other CSS units . |
|
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Thêm ví dụ
Ví dụ
Cách định vị hình nền lên trên cùng:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position-y: bottom;
}
Hãy tự mình thử »Ví dụ
Cách định vị hình nền trên trục y bằng phần trăm:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position-y: 50%;
}
Hãy tự mình thử »Ví dụ
Cách định vị hình nền trên trục y bằng pixel:
body
{
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position-y: 80px;
}
Hãy tự mình thử »Trang liên quan
Hướng dẫn CSS: Nền CSS
Tham chiếu CSS: thuộc tính hình nền
Tham chiếu CSS: thuộc tính vị trí nền
Tham chiếu CSS: thuộc tính nền-vị trí-x
Tham chiếu DOM HTML: thuộc tính BackgroundPosition