Use of <picture> inside <figure> element in HTML5?

烂漫一生 提交于 2021-02-04 09:56:30

问题


In HTML5 we currently have a <figure> element, defined like so (W3C reference)

The figure element represents a unit of content, optionally with a caption, that is self-contained, that is typically referenced as a single unit from the main flow of the document, and that can be moved away from the main flow of the document without affecting the document’s meaning.

Recently a new element <picture> was proposed by the Responsive Images Community group and it was defined in the reference like so

The picture element used for displaying an image that can come from a range of sources (see srcset attribute). Which image the user agent displays depends on the algorithm for deriving the source image.

Since the two descriptions seems to be not contradictory (and documentation on picture is on draft state yet) here my question: is it possible (technically and semantically) to have a nested picture inside a figure element, in this way?

<figure>
   <picture>
      <source ...>
      <source ...>
      <source ...>
      <img..>
   </picture>

   <figcaption>...</figcaption>
</figure>

I've found no references about it in specs. :\

Note: I'm aware that no browser implements currently this element, I'm just making some experiments with jQuery picture

Thank you.


回答1:


You won't find it since it's not actually official yet, but I am going to assume the answer is yes, that is fine.

At the moment, you do something like:

<figure>
  <img src="image.jpg" alt="The Image">
  <figcaption>A Caption</figcaption>
</figure>

and <picture> is simply meant to be the a method of have a multiple src'd <img> for responsive sites, so technically it would seem like -- if it were approved -- your example is valid.




回答2:


Mat Marquis here—I’m one of the editors on the picture spec ( http://picture.responsiveimages.org ).

The short answer is “yes,” the long answer is “definitely.” Semantically correct (figure can contain images, charts, tables, code snippets, and so on), and 100% valid.




回答3:


Yes, you are correct in including <picture> in <figure> tag. I will substantiate this with an endorsement by Google in one of its course.

This is shown in this video

https://youtu.be/StKZMBURZpk?t=29



来源:https://stackoverflow.com/questions/12899691/use-of-picture-inside-figure-element-in-html5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!