我正在制作一个非常基本的图像幻灯片。我只是将背景图像更改为所选的任何图像。但是,当我第一次更改图像时,backgroundSize: cover
似乎消失了。当我再次更改它时,它也不会回来。我真的不明白这种行为...
这是我在stackblitz上的代码的链接:https://stackblitz.com/edit/angular-3wihf2
这是演示的链接:https://angular-3wihf2.stackblitz.io
当我使用background-size: cover
添加一个CSS类时,它也不起作用
谢谢您的帮助!
答案 0 :(得分:1)
更改
[ngStyle]="{height: height + 'px', background: 'url(' + shownImage.path + ') no-repeat center center', backgroundSize: 'cover'}"
到
[ngStyle]="{height: height + 'px', background: 'url(' + shownImage.path + ') no-repeat center center / cover'}"
backgroundSize
不是有效的属性,相反,您可以在background-size
属性本身内的background
值前加一个斜杠/
,以使其与位置({{ 1}})值。