我需要在div上设置此属性:
background: url();
background-repeat: no-repeat;
background-size: cover;
background-position: center, center;
这是我的div:
<div *ngFor="let orderItems of receiptItems;" class="order-article animated bounceInLeft">
<div class="order-img" [style.background]="'url('+ orderItems.product.img.url +')'" ></div>
<div class="order-title">
<p>{{orderItems.product.title}}</p>
</div>
</div>
如您所见,我已经设置了[style.background] url
,但我不知道如何设置其余属性/多个属性。
谢谢 任何帮助都会很棒!
--------编辑:
<div *ngFor="let orderItems of receiptItems;" class="order-article animated bounceInLeft">
<div class="order-img" [ngStyle]="{'background':'url('+ orderItem.product.imgUrl +')', 'background-repeat':' no-repeat','background-size': 'cover;','background-position': 'center, center' }" ></div>
<div class="order-title">
<p>{{orderItems.product.title}}</p>
</div>
</div>
使用ngStyle导致此:
属性未正确应用...
答案 0 :(得分:1)
使用ngStyle
标记
<div [ngStyle]="{'background-image':'url( orderItem.product.imgUrl )', 'background-repeat':' no-repeat','background-size': 'cover','background-position': 'center, center' }" class="order-img" ></div>
答案 1 :(得分:0)
尝试一下。
CSS
.order-img{
background: url(--content);
background-repeat: no-repeat;
background-size: cover;
background-position: center, center;
}
HTML
<div *ngFor="let orderItems of receiptItems;" class="order-article animated bounceInLeft">
<div class="order-img" [attr.outage-count]="orderItems.product.img.url" ></div>
<div class="order-title">
<p>{{orderItems.product.title}}</p>
</div>
</div>