繁体   English   中英

HTML Head元素未在w3.org验证程序上正确注册?

[英]HTML Head element not properly registering on w3.org validator?

我正在学习html,我的讲师告诉我们使用w3.org html验证器来帮助检查代码。 我正在使用一个简单的网页来启动,并且一切正常,但是当我将其放入验证器时,它给出了错误,我完全感到困惑。

我的代码的开头是

<!DOCTYPE html>
<html>
<!-- Html is the element but tag is html + the open/close tags-->
<head>
<title> Around the World Music </title>
<img src="worldmusiclogo.jpg" alt="Around the World Music logo" title="Around the World Music Logo" >
<style>
h1 {
color: red;
}
h2 {
color: orange;
}
</style>
</head>

<body>
....rest of code

验证器输出为

Info: The Content-Type was text/html. Using the HTML parser.

Info: Using the schema for HTML with SVG 1.1, MathML 3.0, RDFa 1.1, and ITS 2.0 support.

Error: Element style not allowed as child of element body in this context. (Suppressing further errors from this subtree.)

From line 12, column 1; to line 12, column 7

Logo" >↩↩↩<style>↩h1 {↩

Contexts in which element style may be used:
    If the scoped attribute is absent: where metadata content is expected.
    If the scoped attribute is absent: in a noscript element that is a child of a head element.
    If the scoped attribute is present: where flow content is expected, but before any other flow content other than inter-element whitespace and style elements, and not as the child of an element whose content model is transparent.
Content model for element body:
    Flow content.

Error: Stray end tag head.

From line 20, column 1; to line 20, column 7

↩</style>↩</head>↩↩<bod

Error: Start tag body seen but an element of the same type was already open.

From line 22, column 1; to line 22, column 6

↩</head>↩↩<body>↩<!--T

看来问题在于验证器将某些代码解释为<style>之前的头端。 因此,它认为样式在错误的位置, <body> ,然后我的</head><body>标签是多余的。 有人可以指出我做错了什么吗?

<img>不能是<head>的后代—删除该元素或将其移动到<body>

您的head有一个img ,如果您想设置一个图标,请尝试使用:

<link rel="icon" type="image/png" href="logo.png" />

head

暂无
暂无

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

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