Html html验证器中的“杂散开始标签页脚”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18939685/
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
"Stray start tag footer" in html validator?
提问by Hayley van Waas
I cannot work out why I am getting this error:
我无法弄清楚为什么会出现此错误:
Stray start tag footer.
杂散的开始标记页脚。
This is the code (I took the content out, this is just the tags)
这是代码(我把内容拿出来,这只是标签)
<!doctype html>
<head>
<title>title</title>
<meta charset="UTF-8">
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<img src="heading.jpg" width="840" alt="pic">
<!--<div id="container"></div> used ot set width of page -->
<nav>
<div id="columns">
<a href="index.html">Home</a>
<a href="products.html">Products</a>
<a href="gift_ideas.html">Gift Ideas</a>
</div>
<br>
<div id="link">
<a href="link1.html">link1</a>|<a href="link2.html">link2</a>|<a href="link3.html">link 3</a>
</div>
</nav>
<section>
<br>
<div id="homePage">
<h1>Welcome</h1>
<br>
<div id="cart">
<img src>
</div>
</div>
</section>
</body>
<footer>
<br>
<h2>Contact Us</h2>
Email: <a href="[email protected]">[email protected]</a>
<img src>
</footer>
I am sure i have closed every tag, so what is the problem with the footer?
我确定我已经关闭了每个标签,那么页脚有什么问题?
回答by Jukka K. Korpela
You need to move the </body>
end tag at the very end, because a footer
element must not appear after the body
element but inside it. This follows from the syntax of the root element, the html
element: it contains a head
element and a body
element, nothing more.
您需要在</body>
最后移动结束标记,因为footer
元素不能出现在body
元素之后,而是出现在元素内部。这遵循根元素的语法,html
元素:它包含一个head
元素和一个body
元素,仅此而已。
The validator says “Stray start tag footer” because the start tag appears in a context where no elements can be started – after the </body>
tag, where only the optional </html>
tag may appear.
验证器说“Stray start tag footer”是因为开始标签出现在没有元素可以开始的上下文中——在</body>
标签之后,只有可选</html>
标签可能出现。
回答by Sean Ryan
Missing <html>
tags added, <footer>
brought inside <body>
tag. While not directly related to your question, it would also appear you are using <br>
tags to make space between various elements. I would suggest you stop doing that, and use CSS to adjust the margin
properties of those elements instead.
<html>
添加<footer>
了缺少的标签,带入了<body>
标签。虽然与您的问题没有直接关系,但您似乎也在使用<br>
标签在各种元素之间留出空间。我建议你停止这样做,margin
而是使用 CSS 来调整这些元素的属性。
Complete code below:
完整代码如下:
<!doctype html>
<html>
<head>
<title>title</title>
<meta charset="UTF-8">
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<img src="heading.jpg" width="840" alt="pic">
<!--<div id="container"></div> used ot set width of page -->
<nav>
<div id="columns">
<a href="index.html">Home</a>
<a href="products.html">Products</a>
<a href="gift_ideas.html">Gift Ideas</a>
</div>
<br>
<div id="link">
<a href="link1.html">link1</a>|<a href="link2.html">link2</a>|<a href="link3.html">link 3</a>
</div>
</nav>
<section>
<br>
<div id="homePage">
<h1>Welcome</h1>
<br>
<div id="cart">
<img src>
</div>
</div>
</section>
<footer>
<br>
<h2>Contact Us</h2>
Email: <a href="[email protected]">[email protected]</a>
<img src>
</footer>
</body>
</html>