html - 如何在角度模板而不是css文件中添加背景图像
问题描述
嗨,你能告诉我如何使用 ngfor 幻灯片/网格类添加角度背景图像是轮播。
<div class="slide slick-bg s-bg-1" *ngFor="let movie of nowPlaying" style="https://image.tmdb.org/t/p/w500/{{movie?.poster_path}}">
<div class="slider-inner h-100">
<h1 class="slider-text big-title title text-uppercase">{{movie?.title}</h1>
<p data-animation-in="fadeInUp" data-delay-in="1.2">
{{movie?.overview}}
</p>
</div>
</div>
.slick-bg { padding: 100px 0 50px;width:100%; background-size: cover;background-position: center center; background-repeat: no-repeat; height: 90vh; position: relative; z-index: 1;}
.s-bg-1 { background-image: url(../images/slider/slider1.jpg); } // need to add this class url here.. https://image.tmdb.org/t/p/w500/{{movie?.poster_path}}
解决方案
您需要使用正确的角度属性来添加动态背景图像
<div class="slide slick-bg s-bg-1" *ngFor="let movie of nowPlaying" [ngStyle]="{'background-image': 'url(https://image.tmdb.org/t/p/w500/' + movie?.poster_path + ')'}">
<div class="slider-inner h-100">
<h1 class="slider-text big-title title text-uppercase">{{movie?.title}}</h1>
<p data-animation-in="fadeInUp" data-delay-in="1.2">
{{movie?.overview}}
</p>
</div>
</div>
推荐阅读
- css - Rubik Black 无法正常工作或无法加载
- opentracing - 在 jaeger 跟踪中未对跟踪进行采样
- java - 无需使用 byte[] 即可立即从流中提取 Java zip 文件
- wordpress - AWS:设置云端并颁发证书。仍然不安全
- resize - 如何恢复虚拟机?失去了最后两个月的工作
- reactjs - React 在侧边栏中实现活动菜单项
- javascript - 为什么我的极小极大算法不会阻止我的移动?
- python - Python:将科学数转换为毫秒
- sql - 如何汇总表头明细表中的总计
- powershell - Powershell仅删除csv标题中的空格