我有通常的css
風格等:內聯CSS到角2 - 線性梯度到背景圖像
.main-body {
height: stretch;
background-size: 100%;
background-repeat: no-repeat;
background-image: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.6) 100%), url('../assets/img/background.png');
}
在上文中,我需要移動
background-image: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%,rgba(0,0,0,0.6) 100%), url('../assets/img/background.png');
內聯造型。我想,如下做到這一點:
UPDATE:
<div class="container-fluid main-body" [ngStyle]="{'background-image': 'linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.6) 100%), url(backgroundUrl)'}">>
</div>
但是,這是行不通的。它正在選擇正確的樣式,但是,它無法找到組件中定義的backgroundUrl
。
答案:
好的,發現了錯誤。只需要如下使用它:
<div class="container-fluid main-body" [ngStyle]="{'background-image': 'linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.6) 100%), url('+backgroundUrl+')'}">
</div>
這是相當接近,但是,網址仍然沒有得到承認。我試圖將它作爲變量傳遞,但仍然無法正常工作。查看更新。 – swdon