首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在角度材料卡片中使用像素

问如何在角度材料卡片中使用像素
EN

Stack Overflow用户
提问于 2019-08-05 22:55:18
回答 1查看 12K关注 0票数 2

如何将图片元素与角度素材卡进行组合?

在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元素:

代码语言:javascript
复制
<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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-06 16:20:33

使用example stackblitz given on material's website,您可以执行以下操作来获得您想要的内容……

代码语言:javascript
复制
  <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:

代码语言:javascript
复制
<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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57361145

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档