background
background 是一种 CSS 简写属性,用于一次性集中定义各种背景属性,包括 color, image, origin, size, repeat 等。
uni-app x 兼容性
| Web | Android | iOS | HarmonyOS | HarmonyOS(Vapor) |
| 4.0 | 3.9 | 4.11 | 4.61 | 5.0 |
拍平兼容性
| Android(Vapor) | iOS(Vapor) | HarmonyOS(Vapor) |
| 5.1 | 5.1 | 5.0 |
语法
示例源码如下,请查看 pre > code 标签中的内容
background: [ <bg-layer> , ]* <final-bg-layer>;
值限制
background 的属性值
| 名称 | 兼容性 | 描述 |
| fixed | |
Web
|
Android
|
iOS
|
HarmonyOS
|
HarmonyOS(Vapor)
| | 4.0 | x | x | x | x |
| 背景固定于视口。在分页媒体中,如果没有视口,则“fixed”背景将相对于页面框固定,因此在每一页都会复制。 |
| local | |
Web
|
Android
|
iOS
|
HarmonyOS
|
HarmonyOS(Vapor)
| | 4.0 | x | x | x | x |
| 背景相对于元素内容固定:如果元素具有滚动机制,背景将随元素内容滚动。 |
| none | |
Web
|
Android
|
iOS
|
HarmonyOS
|
HarmonyOS(Vapor)
| | 4.0 | x | x | x | x |
| 被视为图像层,但不绘制任何内容。 |
| scroll | |
Web
|
Android
|
iOS
|
HarmonyOS
|
HarmonyOS(Vapor)
| | 4.0 | x | x | x | x |
| 背景固定于元素自身,不随内容滚动(实际上附加在元素的边框上)。 |
参见