如何为
中的图像添加标题当处于
时只允许内联元素?
这对我来说是新的: 中只允许内联元素。
,HTML 格式。那么如何为 HTML 段落中的图像添加标题呢?我有这个,但它使用了一个 div,这在
中是不允许的:
<div class='image floatright' style='width:228px;margin:0 0 0 10px;'>
<a rel='article' href='images/articles/comenius_logo.jpg' title=''>
<img style='width:218px' src='images/articles/comenius_logo.jpg' alt='' />
</a>
Caption of the image
</div>
我可以将其放在段落之外,但随后它会位于顶部,但我并不总是这样做想。 我也可以使用 div 代替段落,但这样 html 源代码的语义就会丢失。
我不知道我能做什么:\ 我发现的所有解决方案都使用块元素,如 table、div、figure 等。
This is new for me: only inline elements are allowed in <p> </p>
, in HTML. Then how can I make captions for images in my HTML paragraphs? I have this, but it uses a div, which is not allowed in <p>
:
<div class='image floatright' style='width:228px;margin:0 0 0 10px;'>
<a rel='article' href='images/articles/comenius_logo.jpg' title=''>
<img style='width:218px' src='images/articles/comenius_logo.jpg' alt='' />
</a>
Caption of the image
</div>
I could place this outside the paragraph, but then it would be at the top, which I don't always want.
And I also could use divs instead of paragraphs, but then the semantics of the html source code would be lost.
I don't know what I can do :\ All of the solutions I have found use block elements, like table, div, figure, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
替换为
,然后使用
display:block;
对其进行样式设置。仍然是一个内联元素(即使它看起来像一个块级元素),因此通过了 HTML 验证。
You can replace
<div>
with a<span>
, then style it usingdisplay:block;
. The<span>
is still an inline element (even if it looks like a block-level element), thus passes the HTML validation.