gpt4 book ai didi

html - 在 或其 中设置 `width` 和 `height` 属性有什么作用吗?

转载 作者:可可西里 更新时间:2023-11-01 12:57:12 24 4
gpt4 key购买 nike

我想开始在我的网站上使用 WebP。我正在转换看起来像这样的代码:

<img src="example.jpg" width="100" height="100" alt="Example">

编写如下所示的代码:

<picture>
<source srcset="example.webp" type="image/webp">
<img src="example.jpg" width="100" height="100" alt="Example">
</picture>

放置width的正确位置在哪里?和 height属性?只使用 heightwidth <img> 中的属性元素工作,即使是 <source>图像被选中?

最佳答案

是的,使用 heightwidth <img> 中的属性元素(和其他任何地方)确实按预期工作。您无需尝试在 <picture> 上设置任何属性元素。

运行此代码片段以证明:

<p><code>&lt;img&gt;</code> without <code>height</code> and <code>width</code> attributes:</p>
<picture>
<source srcset="https://a.webpurr.com/Ql62.webp" type="image/webp">
<img src="/image/mraCN.jpg" alt="Example">
</picture>
<p><code>&lt;img&gt;</code> with <code>height</code> and <code>width</code> attributes:</p>
<picture>
<source srcset="https://a.webpurr.com/Ql62.webp" type="image/webp">
<img src="/image/mraCN.jpg" width="100" height="100" alt="Example">
</picture>

(如果您看到标有“JPEG”的图片,则说明您使用的浏览器不支持 WebP。如果您看不到图片,可能图片托管网站 webpurr.com 已关闭。)

关于html - 在 <picture> 或其 <img> 中设置 `width` 和 `height` 属性有什么作用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48193835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com