更改背景图片后,BackgroundSize不起作用

时间:2020-02-25 15:41:57

标签: angular typescript

我正在制作一个非常基本的图像幻灯片。我只是将背景图像更改为所选的任何图像。但是,当我第一次更改图像时,backgroundSize: cover似乎消失了。当我再次更改它时,它也不会回来。我真的不明白这种行为...

这是我在stackblitz上的代码的链接:https://stackblitz.com/edit/angular-3wihf2

这是演示的链接:https://angular-3wihf2.stackblitz.io

当我使用background-size: cover添加一个CSS类时,它也不起作用

谢谢您的帮助!

1 个答案:

答案 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}})值。

Forked Stackblitz