【问题标题】:ngStyle background image not visiblengStyle 背景图片不可见
【发布时间】:2020-04-24 08:05:40
【问题描述】:

我遇到了以下问题:我想使用 ngStyle 将背景图片插入我的网站。以下代码工作正常:

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

但是,如果我想为背景图像添加更多“属性”,则图像不再可见:

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

【问题讨论】:

    标签: angular background ng-style


    【解决方案1】:

    background-image 属性为一个元素设置一个或多个背景图像

    如果您想添加更多“属性”,请改用 background

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

    【讨论】:

    • @Felixbrandi 不客气!如果有帮助,请不要忘记接受答案。谢谢
    猜你喜欢
    • 2019-07-31
    • 2013-08-18
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    • 2012-03-31
    • 2019-11-26
    • 2016-07-28
    • 2017-01-02
    相关资源
    最近更新 更多