标签在it技术中的作用是什么?

4
我明白文章标签是“独立的内容节”,具体信息请参考www.w3.org/wiki/HTML/Elements/article。
我有一个只包含博客文章的页面。该博客文章顶部有一张图片和标题说明(这张图片用来说明博客文章中的内容)。这个图片和标题说明应该放在article标签内还是外面呢?
图片:
<img src="1.png">
<div>Caption of the image</div>

博客文章简述:
<article>
<h1>Title of the post</h1>
<div>Last Updated: 2016-01-07</div>
<div>       
    <p>This is the body of the post</p>
</div>
<p>Author of the post</p>
</article>
3个回答

6
您可能需要检查figurefigcaption标签。
文档中的示例:
<figure>
  <img src="https://developer.cdn.mozilla.net/media/img/mdn-logo-sm.png" alt="An awesome picture">  
  <figcaption>Fig1. MDN Logo</figcaption>
</figure>

如果figurearticle相关,则将其放在article标签内。


3

我注意到这个问题已经有了一个被接受的答案,但是我认为它需要更多关于你的问题的信息:

图片和标题应该放在article标签内还是外部?

从语义化HTML的角度来看,图像和标题内容可以嵌套在<article>标签中,因为<article>的允许内容是流内容,而<img><figure>都被定义为流内容。

<article>元素表示自包含内容,这意味着如果除了<article>元素之外,您删除了所有其他HTML,读者仍然能够理解内容。 语义分区 - MDN

请查看下面的代码片段,了解使用<article>标记博客文章并添加嵌套的<img>或更好的方法,如@rafaelbiten建议的<figure>的一种有效方式。

<article>
  <h1>Title of the post</h1>
  <p>Author of the post</p>
  <p>Last Updated: 2016-01-07</p>
  <figure>
    <img src="1.png" alt="Some alt text">
    <figcaption>Caption of the image</figcaption>
  </figure>
  <p>This is the body of the post</p>
</article>


0

如果图片与文章相关,您可以在文章中使用img标签。


你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接