HTML验证器“自动关闭语法";和“非空隙"表示错误 [英] HTML Validator "self-closing syntax" and "non-void" errors

查看:113
本文介绍了HTML验证器“自动关闭语法";和“非空隙"表示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用W3验证程序验证我的代码.我是Web设计的新手.有人能帮我吗.验证者指出:

I am having trouble validating my code with W3 Validator. I am new to Web Design. Can someone help me. The Validator states:

错误:在非无效HTML元素上使用的自动关闭语法(/>).忽略斜杠并将其视为开始标记.

Error: Self-closing syntax (/>) used on a non-void HTML element. Ignoring the slash and treating as a start tag.

从第15行第1列开始;到第15行,第41列

From line 15, column 1; to line 15, column 41

p>↩↩↩<h1>↩<a href="http://www.monroecollege.edu:"/><img s

代码:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Home-International Student Home Page</title>
<link href="cssstyle.css" rel="stylesheet">
</head>
<body>

<h3>About Image:</h3>
<p>Monroe College Logo</p>

<h1>
   <a href="http://www.monroecollege.edu:">
   <img src="monroelogo.jpg"  alt="" height="115" width="700"/>
</h1>   

推荐答案

首先,关闭<h1>容器中的anchor(<a>)元素.

First thing, close the anchor (<a>) element in your <h1> container.

无效的HTML

<h1>
    <a href="http://www.monroecollege.edu:">
    <img src="monroelogo.jpg"  alt="" height="115" width="700"/>
    <!-- missing closing </a> tag here -->
</h1>

有效的HTML

<h1>
    <a href="http://www.monroecollege.edu:">
    <img src="monroelogo.jpg"  alt="" height="115" width="700"/>
    </a>
</h1>

确保始终将结束标记添加到非无效(非自我关闭)元素中.检查每个元素的说明,以确定标签遗漏" "要求.

Make sure to always add closing tags to non-void (non-self-closing) elements. Check the description for each element to determine the "tag omission" requirement.

无效元素也称为自闭合单个.这是 HTML中所有无效元素的列表 >

Void elements are also known as self-closing, empty and singleton. Here is a list of all void elements in HTML

area, base, br, col, embed, hr, img, input, keygen, link, meta, param, source, track, wbr

所有其他元素都需要一个结束标记.

All other elements require a closing tag.

此外,对于void元素,不再需要尾部斜杠了.可以接受,但不是必须的.

Also, for void elements, the trailing slash isn't necessary anymore. It's acceptable, but not necessary.

这是有效的HTML:

<br>, <hr>, <img>, <input>, <meta>, etc.

实际上,删除斜杠是 Google HTML/CSS样式指南推荐堆栈溢出社区.

In fact, removing the slash is recommended by the Google HTML/CSS Style Guide and the Stack Overflow community.

此外,将图像放入标题元素(在这种情况下为<h1>)完全有效.这是否正确是另一个问题.

Also, putting an image inside a heading element (in this case <h1>) is perfectly valid. Whether or not it's the right thing to do is another question.

这篇关于HTML验证器“自动关闭语法";和“非空隙"表示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆