我正在学习 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>
.
关于HTML Head 元素未在 w3.org 验证器上正确注册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32314123/