img标签中的Div标签 [英] Div tag within img tag

查看:418
本文介绍了img标签中的Div标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在每个图像上添加一个文本,并且我有使用img标签构建的图像库。我不能在img标签下附加div标签。类似于这里显示的:

I need to add a text on each of the image and I have the image gallery constructed using img tags. Can't I append div tags under img tags. Similar to the one shown here :

<img id="img1" class="img1_1" src="hello1_1">
  <div class="textDesc">HELLO1_1</div>
</img>

虽然div附加到img标签,但我无法在图像上看到文本HELLO1_1 。

Though the div is appended to img tag , but I cant see the text "HELLO1_1" on the image.

任何人都可以帮我吗?
如果您需要源代码,我可以与您分享。

Please can anyone help me? If you need the source code I can share it with you.

以下是测试场景的链接:
http://jsfiddle.net/XUR5K/9/

Here is the link to test the scenario : http://jsfiddle.net/XUR5K/9/

推荐答案

img 元素有一个自我关闭标签,所以你不能给它子元素,并期望它工作。其内容模型定义为来源

The img element has a self closing tag, so you can't give it child elements and expect it to work. Its content model is defined as empty. Source.

我怀疑您指定的任何孩子将不会呈现,因为 img 元素是一个替换元素,如W3C中所述规格。

I suspect any children you specify won't be rendered because an img element is a replaced element, as mentioned in the W3C spec.

这篇关于img标签中的Div标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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