如何使图像具有响应性?

问题描述

不知道如何让浏览器在某些断点处使用正确的图像。

GitHub repo

<!-- <picture>
        <source sizes="(max-width: 640px) 100vw,640px" srcset="./images/profile1000.avif 1280w,./images/profile.avif 640w,./images/profile120.avif 320w" type="image/avif" />

        <source sizes="(max-width: 640px) 100vw,./images/profile.webp 640w,./images/profile120.webp 320w" type="image/webp" />

        <source sizes="(max-width: 640px) 100vw,./images/profile.png 640w,./images/profile120.png 320w" type="image/png" />

        <img width="421" height="421" decoding="async" loading="lazy" src="./images/profile.png" alt="profile image" class="bg-clip-padding bg-opacity-50 shadow rounded-full bg-white dark:bg-gray-900 backdrop-blur-2xl" />
      </picture> -->

      <picture>
        <source media="(min-width: 2560px)" srcset="./images/profile1000.png,./images/profile1000.webp,./images/profile1000.avif" type="image/avif" />
        <source media="(min-width: 1080px)" srcset="./images/profile.png,./images/profile.webp,./images/profile.avif" type="image/avif" />
        <source media="(min-width: 1024px)" srcset="./images/profile120.png,./images/profile120.webp,./images/profile120.avif" type="image/avif" />
        <img src="./images/profile1000.webp" alt="profile image" decoding="async" loading="lazy" class="bg-clip-padding bg-opacity-50 shadow rounded-full bg-white dark:bg-gray-900 backdrop-blur-2xl" />
      </picture>

解决方法

您应该为每种格式使用单独的源声明并为每种格式指定类型。 请参阅官方指南:https://avif.io/blog/tutorials/use-avif-in-html/

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...