【问题标题】:Ionic 2 - Background image sanitizer and CSS propertyIonic 2 - 背景图像消毒剂和 CSS 属性
【发布时间】:2018-02-04 22:56:13
【问题描述】:

我有一个显示一些卡片的 Ionic 应用程序。 卡片的背景是一张完整的图片。我有这个样式代码:

style="background-image: linear-gradient(rgba(31, 37, 51, 0.6), rgba(31, 37, 51, 0.6)), url('merl')"

但是现在,我需要动态更改我的图片,所以我使用了:

home.html

style="background-image: linear-gradient(rgba(31, 37, 51, 0.6), rgba(31, 37, 51, 0.6))" [style.background-image]="getBackground(event.picture)" 

home.ts

getBackground (image) {
  return this._sanitizer.bypassSecurityTrustStyle(`url(${image})`);
}

问题是我的CSS过滤器没有显示,图片显示没有过滤器。 如何显示 CSS 过滤器?

【问题讨论】:

    标签: html css angular typescript ionic2


    【解决方案1】:

    将您的过滤器添加到getBackground

    类似

    getBackground (image) {
      let cssFilter = 'linear-gradient(rgba(31, 37, 51, 0.6), rgba(31, 37, 51, 0.6))';
      return this._sanitizer.bypassSecurityTrustStyle(`url(${image}), ${cssFilter}`);
    }
    

    有效设置

    background-image: url(...), linear-gradient(rgba(31, 37, 51, 0.6), rgba(31, 37, 51, 0.6))
    

    您当前的方式将是压倒一切的

    background-image: linear-gradient(rgba(31, 37, 51, 0.6), rgba(31, 37, 51, 0.6)) 
    

    background-image: url(...)
    

    【讨论】:

    • 非常感谢,完美运行。 ${cssFilter} 必须放在 ${image} 之前才能工作。很好的解决方案,非常感谢!
    猜你喜欢
    • 2011-09-19
    • 2014-05-25
    • 2017-10-22
    • 2015-09-19
    • 2020-01-15
    • 1970-01-01
    • 2013-06-09
    • 1970-01-01
    • 2010-10-05
    相关资源
    最近更新 更多