在. srcset
_ sizes
_ img
(我正在使用图片填充,但它遵循原始规范)
我有一个图像,在大屏幕上,它是25em
宽度,但在小手机屏幕上,它85%
是它的容器,而不是视口。我不想在较小的屏幕上给它一个固定的大小 - 相反我希望它适应它的容器(它是 a div
)。我无法弄清楚如何做到这一点。
我也很不高兴我必须将大小和媒体查询硬编码到 HTML 中,而不是将它们放在 CSS 中——它将相同的信息放在两个地方。有没有解决的办法?
我有的:
<!--
Is there any way to make the sizes be percentages of the container?
-->
<img
sizes="(min-width: 1000px) 750px, (min-width: 200px) 50vw"
srcset="images/full_0.png 750w, images/small_0.png 187w"
alt="Sizing">
我想要的是:
<!--
The "use-750w" tells it which image to load but NOT the size
to make it. Instead, it lets CSS size the image.
-->
<img
sizes="(min-width: 1000px) use-750w, (min-width: 200px) use-187w"
srcset="images/full_0.png 750w, images/small_0.png 187w"
alt="Sizing">