简体   繁体   English

ngStyle 背景图片不可见

[英]ngStyle background image not visible

I've got the following problem: I want to insert a background image to my website with ngStyle.我遇到了以下问题:我想使用 ngStyle 将背景图像插入到我的网站中。 The following code works fine:以下代码工作正常:

<div [ngStyle]="{'background-image': 'url(' + myBackgroundUrl + ')', 'width': '224px', 'height': '248px'}"></div>

However, if I want to add some more "attributes" to the background-image, the image isn't visible anymore:但是,如果我想向背景图像添加更多“属性”,则图像不再可见:

<div [ngStyle]="{'background-image': 'url(' + myBackgroundUrl + ') no-repeat -228px 0', 'width': '224px', 'height': '248px'}"></div>

The background-image property sets one or more background images for an element . background-image属性为元素设置一个或多个背景图像

If you want to add some more "attributes" then use background instead:如果您想添加更多“属性”,请改用背景

<div [ngStyle]="{
  'background': 'url(' + myBackgroundUrl + ') no-repeat -228px 0', 
  'width': '224px', 
  'height': '248px'
}"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM