h1和跨度 [英] h1 and the span

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

问题描述

虽然在html中使用h1-h6标签,但我不断在w3c验证程序上收到错误消息.我对此并不陌生,我已经尝试了很多次以解决问题,但我做不到.

While using h1-h6 tags in my html, i keep getting error messages on w3c validator. I'm new to this and I've tried so many times to solve the problem but i can't.

该文本在我的网站上看起来很好,但无法验证.我该如何解决这个问题?错误消息如下;

The text appears perfectly fine on my website but it won't validate. How do i solve this problem? The error message is as follows;

第34行,第4列:文档类型 不允许元素"h1"这里;丢失的 对象",小程序",地图"之一, "iframe","button","ins","del" 开始标签

Line 34, Column 4: document type does not allow element "h1" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag

<h1><span> My website </h1>< span>< ----这是我得到错误的代码.

<h1><span> My website </h1>< span> <----this is the code i'm getting the error for.

不允许提及的元素 出现在其中的上下文中 您已经放置了它;另一个提到 元素是唯一的 都允许在那里并且可以包含 提到的元素.这可能意味着 您需要一个包含元素,或者 可能你忘记了 关闭上一个元素.

The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

此消息的一个可能原因是您试图将一个块级元素(例如"

"或")放入一个内联元素(例如,",";"或").

One possible cause for this message is that you have attempted to put a block-level element (such as "

" or "") inside an inline element (such as "", "", or "").

在任何情况下,使用标头标签的最佳方法是什么?我在做什么错了?

In any case what's the best way to use header tags? What am I doing wrong?

推荐答案

  • 跨度是一个内联元素
  • h1是一个块元素
  • 内联元素不能包含block元素
  • 其他元素不能部分包含元素
    • An span is an inline element
    • An h1 is a block element
    • An inline element cannot contain a block element
    • Elements cannot be partially contained by other elements
    • 因此,从DTD的角度来看:

      Therefore, from the perspective of the DTD:

      <h1><span>…</span></h1> <!-- This is fine -->
      <div><h1>…</h1></div>   <!-- This is fine -->
      <h1><span>…</h1></span> <!-- This is wrong -->
      <span><h1>…</h1></span> <!-- This is wrong -->
      

      实际上,解决问题的正确方法取决于您要使用跨度的范围.

      What the right solution to the problem actually is rather depends on what you are trying to use the span for.

      (请注意,上面对block和inline元素的讨论有所简化.请参见如何阅读HTML DTD 全文,特别是内容模型部分

      (Note that the discussion of block and inline elements above is somewhat simplified. See How to read the HTML DTD for the full story, in particular the section on the Content Model)

      这篇关于h1和跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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