我开始阅读有关 html5 的内容,并且正在尝试从事一个项目,以便了解其工作原理。我知道标签可以这样使用:
<figure id="car">
<img src="img/car.jpg" alt="the car">
<p>The car</p>
</figure>
虽然我需要这些图形中的 6 个,但我想使用 sprites 并且(除非我不知道重要的事情)sprites 只有在我添加图像宽度 css(背景图像)时才有效。所以我会做的是:
<figure id="car">
<pre></pre> <!-- add image from css -->
<p>The car</p>
</figure>
我可以像这样使用图形标签吗?
非常感谢
最佳答案
figure 和 figcaption 元素的语义目的相当明确。如果您不关心语义,那么就没有太多理由使用它们。 Div 将工作正常。以下是图形应该的用法:
<figure>
<img src="/image.jpg" alt="A description of what this image is">
<figcaption>A description that may or may not describe the image specifically and accompanies content from within the article.</figcaption>
</figure>
编辑:我应该提一下,带有背景的 pre 可能不是它的预期用途,并且根本不会帮助使用屏幕阅读器的人。搜索引擎的机器人也可能有不同的 react ,这可能对您不利。
关于html - html5中的<figure>标签可以用于背景图片吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7913359/