<img src='Assets/image.png'>some text</img>如果我必须显示“某些文本”,是否可以?
我知道我可以只使用 div 并将 div 设置为显示在图像顶部的样式,但我想知道是否有可能让标签内的文本显示出来。
不。img 内没有文字。根据规范,img 元素是一个空元素,即它没有任何内容或结束标记。
好消息是,在您的示例源中,文本“some text”将显示在页面上。(从技术上讲,它不在 img 内部,因此它只是在之后直接显示。)但这可能不是您想要的......
可能的解决方案是:
alt。title属性figure在其中放置 的元素,img并将文本放置在 中figcaption,并使用 CSS 定位将Figcaption 放置在图像顶部。figure {
position: relative
}
figcaption {
position: absolute;
width: 200px;
line-height: 150px;
text-align: center;
left: 0;
top: 0;
text-shadow: 0 0 1px white;
font-weight:bold;
}Run Code Online (Sandbox Code Playgroud)
<figure>
<img src="http://lorempixel.com/200/150" />
<figcaption>some text</figcaption>
</figure>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15236 次 |
| 最近记录: |