Angular2动态背景图像 [英] Angular2 dynamic background images

查看:479
本文介绍了Angular2动态背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在html模板中,我有这种风格的动态图像:

In the html template I have this style with a dynamic image:

<div style="background: url('/img/{{item.img}}'); width: 200px; height: 150px"></div>

适用于网络浏览器和Android浏览器。但是,使用style =动态的背景图像不会在iPad上显示。

Which works in web browsers and android browser. However background images that are dynamic using "style=" are not showing on iPad.

我总是可以使用img标签创建动态图像,但我正在为iPad寻找样式/ css解决方案。

I could always create dynamic images using the img tag but I'm looking for a style/css solution for iPad.

推荐答案

改为使用

<div [ngStyle]="{background: 'url(/img/' + item.img + ')', width: '200px', height: '150px'"></div>

<div [style.background]="'url(/img/' + item.img + ')'"
    [style.width.px]="200" [style.height.px]="150p"></div>

参见在RC.1中,某些样式无法使用绑定语法添加

这篇关于Angular2动态背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆