如何在 y 轴上定位背景图片:
div {
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-position-y: center;
}
亲自试一试 »
下面有更多 "亲自试一试" 示例。
这个background-position-y
属性设置背景图片在 y 轴上的位置。
提示:默认情况下,一个背景图放置在元素的左上角,并垂直和水平重复。
展示演示❯表中的数字指定完全支持该属性的第一个浏览器版本。
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 |
background-position-y:
value;
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 |
如何将背景图片放置在顶部:
body {
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position-y: bottom;
}
亲自试一试 »
如何使用百分比在 y 轴上定位背景图片:
body {
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position-y: 50%;
}
亲自试一试 »
如何使用像素在 y 轴上定位背景图片:
body {
background-image: url('w3css.gif');
background-repeat: no-repeat;
background-attachment: fixed;
background-position-y: 80px;
}
亲自试一试 »
CSS教程:CSS 背景
CSS 参考:背景图片属性
CSS 参考:背景位置属性
CSS 参考:背景位置 x 属性
HTML DOM 参考:背景位置属性
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!