如何将图片元素与角度素材卡进行组合?
在Angular Material https://material.angular.io/components/card/examples中,您可以使用<img mat-card-image src="../assets/img/shiba2.jpg" alt="Photo">
( mat-card-image指令使图像占据整个卡片的宽度。)
但是当我在图片和/或源元素上引入带有mat-card-image指令的picture元素时,它破坏了CSS,并且似乎该元素在Angular-Material中不受支持。
这是可行的,但始终显示img元素:
<picture>
<source srcset="../assets/img/shiba2.webp" type="image/webp">
<source srcset="../assets/img/shiba2.jpg" type="image/jpg">
<img mat-card-image src="../assets/img/shiba2.jpg" alt="Photo">
</picture>我希望使用图片元素来使用webp图像,并在Safari等不支持的浏览器中使用jpg/png。
发布于 2019-08-06 16:20:33
使用example stackblitz given on material's website,您可以执行以下操作来获得您想要的内容……
<picture>
<source media='(min-width:0px)' srcset="https://material.angular.io/assets/img/examples/shiba2.jpg">
<img mat-card-image src="" alt="Photo of a Shiba Inu">
</picture>material网站上stackblitz示例的相关HTML:
<mat-card class="example-card">
<mat-card-header>
<div mat-card-avatar class="example-header-image"></div>
<mat-card-title>Shiba Inu (using <code>picture</code> tag)</mat-card-title>
<mat-card-subtitle>Dog Breed</mat-card-subtitle>
</mat-card-header>
<picture>
<source media='(min-width:0px)' srcset="https://material.angular.io/assets/img/examples/shiba2.jpg">
<img mat-card-image src="" alt="Photo of a Shiba Inu">
</picture>
<mat-card-content>
<p>
The Shiba Inu is the smallest of the six original and distinct spitz breeds of dog from Japan.
A small, agile dog that copes very well with mountainous terrain, the Shiba Inu was originally
bred for hunting.
</p>
</mat-card-content>
<mat-card-actions>
<button mat-button>LIKE</button>
<button mat-button>SHARE</button>
</mat-card-actions>
</mat-card>https://stackoverflow.com/questions/57361145
复制相似问题