如何为

中的图像添加标题当处于

时只允许内联元素?

发布于 2024-12-19 08:37:29 字数 591 浏览 3 评论 0原文

这对我来说是新的:

中只允许内联元素。

,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糖 2024-12-26 08:37:29

您可以将

替换为 ,然后使用 display:block; 对其进行样式设置。 仍然是一个内联元素(即使它看起来像一个块级元素),因此通过了 HTML 验证。

You can replace <div> with a <span>, then style it using display:block;. The <span> is still an inline element (even if it looks like a block-level element), thus passes the HTML validation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文