Html HTML5 验证错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9991174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML5 Validation Errors
提问by Hyman-T
I have a bit of problem when trying to validate my page as HTML5. There are two errors. The first says, 'Element head is missing a required instance of child element title', and the second error is, 'Element hr not allowed as child of element ul in this context. (Suppressing further errors from this subtree)'.
尝试将我的页面验证为 HTML5 时遇到了一些问题。有两个错误。第一个说,“元素头缺少子元素标题的必需实例”,第二个错误是,“在此上下文中,元素 hr 不允许作为元素 ul 的子元素”。(抑制来自该子树的更多错误)'。
Here is my source code
这是我的源代码
<!DOCTYPE html>
<html lang="en">
<head>
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="core/css/style.css">
</head>
<body>
<nav>
<h1>Name</h1>
<ul>
<hr>
<li><a href=".."><img src="core/images/home.png" alt="Home"></a></li>
<hr>
<li><a href=".."><img src="core/images/about.png" alt="About"></a></li>
<hr>
<li><a href=".."><img src="core/images/projects.png" alt="Projects"></a></li>
<hr>
</ul>
</nav>
-Thank you in advance for any help
-预先感谢您的任何帮助
回答by Dunhamzzz
As Juhana's comment points out the errors are self-explanatory:
正如 Juhana 的评论所指出的,这些错误是不言自明的:
Element head is missing a required instance of child element title
元素头缺少子元素标题的必需实例
This means you are simply missing a <title>
tag in your <head>
tags. You should definitely give your page a title!
这意味着您只是在<title>
标签中缺少一个<head>
标签。你绝对应该给你的页面一个标题!
Element hr not allowed as child of element ul in this context
在此上下文中,元素 hr 不允许作为元素 ul 的子元素
By there very nature, <ul>
(unordered list) tags can only contain <li>
(list item) tags. You are wrong to use a horizontal-rule inside your list. You can achieve the same effect with CSS. I suggest read a few more tutorials on HTML and basic CSS.
本质上,<ul>
(无序列表)标签只能包含<li>
(列表项)标签。在列表中使用水平规则是错误的。您可以使用 CSS 实现相同的效果。我建议阅读更多关于 HTML 和基本 CSS 的教程。
回答by Hyman-T
I had the same problem with <hr>
tags inside an <ul>
. Instead of applying new css rules to your list you just have to contain <hr>
inside of a <li>
.
我<hr>
在<ul>
. 不必将新的 css 规则应用到您的列表中,您只需将其包含<hr>
在 .css 文件中<li>
。
<ul>
<li><hr/></li>
<li>text</li>
</ul>
Then all of your elements inside of a <ul>
are properly nested and contained. No extra work necessary.
然后 a 中的所有元素<ul>
都被正确嵌套和包含。不需要额外的工作。