【发布时间】:2021-01-13 02:04:12
【问题描述】:
我一直在使用 ngStyle...
添加背景图片<div class="modal-header" [ngStyle]="{
background: 'url(api/myfile'
+ filteredProducts[index].imageURL + ')'}">
但是,这个 css 无效
.modal-header {
background-size: cover;
}
如果我直接使用普通的背景图片
.modal-header {
background-size: cover;
background-image: url('imageurl');
}
我试图以角度添加背景大小,但这只是尖叫错误,因为我必须将 background-size 放在引号中以便编译器接受它
[ngStyle]="{background: 'url(api/myfile?filename='
+ filteredProducts[index].imageURL + ')', 'background-size': cover}"
我终于尝试使用此属性,但所有这些都失败了
[style.background-size]="cover"
这也没用
<div class="modal-header" [ngStyle]="
{
'background-image': 'url(url'
+ filteredProducts[index].imageURL+')',
'background-size': 'cover',
'background-position': 'center'
}
">
【问题讨论】: