< PICTURE>的备用图片> [英] Fallback picture for <PICTURE>

查看:86
本文介绍了< PICTURE>的备用图片>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML5中正式使用< PICTURE> 吗?我无法在w3schools.com上找到它。



假设它是官方的,则后备< img> 元素 src srcset 。我看到一些使用 srcset 的网站,它们在任何版本的IE中都不起作用,但是 src 可以工作IE浏览器。 < picture> 标记目前已被纳入给出了更深入的内容分析不同的响应图像技术以及何时使用每一种技术。






Aside:Please不要相信W3School作为官方来源。 W3School选择了一个与W3C(万维网联盟)类似的名称,但事实上它们并不与官方标准组织相关。从他们的大约页面:该网站的名称来自万维网(W3) ,但不隶属于W3C。


Is <PICTURE> officially in HTML5? I can't find it in w3schools.com.

Assuming it is official, is the source attribute of the fallback <img> element src or srcset. I am seeing some web sites using srcset and they don't work in any version of IE, but src works in IE.

解决方案

Yes, the <picture> tag is an official part of the standard, but HTML5 is a living standard, and this tag is considered "experimental".

The <picture> tag is currently accepted into the WHATWG HTML5 Living Standard. That does not mean it is set in stone, and it is still considered an "experimental technology". You should not depend on browsers to support this technology. You can see an (unofficial) overview of browser support here.

As stated on the Mozilla Developer's Network:

This is an experimental technology. Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.

The "living standard" model of standardizing HTML means that elements are accepted more easily but may not remain in the standard or may be changed if a good argument is made against their current use.

The <img> element must be included, and this has the side-effect of offering a fall-back option.

The picture element, by necessity, must have an <img> tag inside it, alongside the <source> elements. This has the side-effect of providing a fall-back option, but is also necessary to provide the base image and metadata (especially to provide the required alt attribute). The <source> elements merely override the src attribute of the <img> tag (under specified circumstances).

Here is an example of the picture element, used properly. This example comes from the Mozilla Developer's Network.

<picture>
 <source srcset="mdn-logo-wide.png" media="(min-width: 600px)">
 <img src="mdn-logo-narrow.png" alt="MDN">
</picture>

The src attribute should always be included, even if you use the srcset attribute in addition.

The srcset attribute is (from what I understand) an "older" technique of defining sources for different resolutions. It does not use standard-syntax media queries or have the other flexibilities afforded by using the <picture> and <source> elements (although Chris Coyier of CSS-tricks disagrees with me here), but may be supported by some browsers which don't support the newer standard. Including the srcset attribute on your <img> tag might be desirable, but, in these cases, you still need to include the src attribute as well (which provides a default when none of the srcset files are appropriate, and provides a fall-back for browsers that don't support srcset). All image tags always need src and alt attribute -- these are required attributes for the <img> tag.

A valid example of the <picture> tag, including the srcset attribute as a fall-back, and the src attribute as a worst-case-scenario fall-back, is below.

<picture>
 <source srcset="mdn-logo-wide.png" media="(min-width: 600px)">
 <img src="mdn-logo-narrow.png" srcset="mdn-logo.png 2x" alt="MDN">
</picture>


This Smashing Magazine article gives a much more in-depth analysis of the different responsive images techniques and when to use each one.


Aside: Please don't trust W3Schools as an official source. W3Schools chose a name that is similar to W3C (the World Wide Web Consortium), but they are not, in fact, related to the official standards body. From their about page: "The site derives its name from the World Wide Web (W3), but is not affiliated with the W3C."

这篇关于&lt; PICTURE&gt;的备用图片&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆