【发布时间】:2022-01-03 13:33:39
【问题描述】:
我有很多 image/webp 图像,并希望浏览器有一个用于 Safari 的后备 image/jpg。
由于某种原因,Chrome(以及其他所有浏览器)仍在使用 jpg 图像而不是 webp。
<picture>
<source class="content_image" height="150" width="150" src="<?php echo get_stylesheet_directory_uri();?>/assets/pictures/section/logo_dsv_150x150.webp" type="image/webp">
<source class="content_image" height="150" width="150" src="<?php echo get_stylesheet_directory_uri();?>/assets/pictures/section/logo_dsv_150x150.png" type="image/png">
<img height="150" width="150" src="<?php echo get_stylesheet_directory_uri();?>/assets/pictures/section/logo_dsv_150x150.png" alt="lorem ipsum">
</picture>
我也将它与 ACF 结合使用:
<?php
$image_02_jpg = get_field('content_picture_02_jpg');
$image_02_webp = get_field('content_picture_02_webp');
?>
<picture>
<source class="content_image" width="679" height="450px" src="<?php echo $image_02_webp['url']; ?>" type="image/webp">
<source class="content_image" width="679" height="450px" src="<?php echo $image_02_jpg['url']; ?>" type="image/jpeg">
<img class="content_image" width="679" height="450px" src="<?php echo $image_02_jpg['url']; ?>" alt="content_image">
</picture>
【问题讨论】:
-
@NicoHaase 您添加的所有链接都与基于
media属性选择图像的位置相关。原帖中没有media属性。
标签: html image jpeg webp fallback