下面一行有些不对劲。我的高度和宽度正确显示在我的应用程序中。如果我包含 + character.offsetX + 'px' + character.offsetY + 'px'
背景图像样式不会出现。
Character.offsetX 和 offsetY 是字符对象提供的硬编码数字。
我在网上找到的示例非常简单,没有显示如何使用 background-image
的简写版本来设置 background-position
<li *ngFor="let character of this.characterList" [ngStyle]= "{'height':'50px', 'width':'50px', 'background-image':'url(' + character.fullImagePath + ')' + character.offsetX + 'px' + character.offsetY + 'px' }"
最佳答案
background-image
不允许设置其他 background-*
属性 - 您需要使用 background
代替它的简写:
<li *ngFor="let character of this.characterList" [ngStyle]= "{'height':'50px', 'width':'50px', 'background':'url(' + character.fullImagePath + ') ' + character.offsetX + 'px ' + character.offsetY + 'px' }"
关于html - 为背景图像速记正确格式化 ng-style,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56572613/