简体   繁体   English

h1和跨度

[英]h1 and the span

While using h1-h6 tags in my html, i keep getting error messages on w3c validator. 在我的html中使用h1-h6标签时,我不断在w3c验证器上收到错误消息。 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; 错误信息如下;

Line 34, Column 4: document type does not allow element "h1" here; 第34行,第4列:文档类型不允许元素“h1”在这里; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag 缺少“object”,“applet”,“map”,“iframe”,“button”,“ins”,“del”start-tag

<h1><span> My website </h1>< span> <----this is the code i'm getting the error for. <h1><span> My website </h1>< span> <----这是我收到错误的代码。

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? 我究竟做错了什么?

  • An span is an inline element span是一个内联元素
  • An h1 is a block element h1是块元素
  • An inline element cannot contain a block element 内联元素不能包含块元素
  • Elements cannot be partially contained by other elements 元素不能被其他元素部分包含

Therefore, from the perspective of the DTD: 因此,从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. 问题的正确解决方案实际上取决于您尝试使用跨度的内容。

(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) (请注意,上面对块和内联元素的讨论有些简化。请参阅如何阅读完整故事的HTML DTD ,特别是有关内容模型的部分)

You're closing your tags in the wrong order: 您正以错误的顺序关闭代码:

<H1><span> My website </h1></span>

should be 应该

<h1><span>My website</span></h1>
<h1 style="display:inline;">Bold text goes here</h1> <h2 style="display:inline;">normal text goes here</h2>

如果您查看内联H1标签,请使用上述内容

you cannot spit an element with another element 你不能用另一个元素吐出一个元素

< H1>< span> My website < /h1>< /span>

should be this 应该是这个

< H1>< span> My website < /span>< /h1>

did you try to write this? 你试着写这个吗?

<h1><span> My website </span></h1>

you should close the tags in the same order you open them. 您应该按照打开它们的顺序关闭标记。

Your elements are not nesting correctly. 您的元素未正确嵌套。

Think of them like different types of brackets. 把它们想象成不同类型的括号。

If <h1></h1> is like {} and <span></span> is like [] , then you have 如果<h1></h1>类似于{}<span></span>就像[] ,那么你有

 { [ My website } ]

As you can see, the brackets are off. 如您所见,括号已关闭。

You want 你要

 <h1><span>My website</span></h1>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM