HTML 验证器“自闭合语法"和“非空"错误 [英] HTML Validator "self-closing syntax" and "non-void" errors

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

问题描述

我在使用 W3 Validator 验证我的代码时遇到问题.我是网页设计的新手.有人能帮我吗.验证器声明:

<块引用>

错误:用于非空 HTML 元素的自闭合语法 (/>).忽略斜线并将其视​​为开始标记.

来自第 15 行,第 1 列;到第 15 行,第 41 列

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

代码:

<头><meta charset="utf-8"><title>首页-国际学生主页</title><link href="cssstyle.css" rel="stylesheet"><身体><h3>关于图片:</h3><p>门罗学院标志</p><h1><a href="http://www.monroecollege.edu:"><img src="monroelogo.jpg" alt="" height="115" width="700"/>

解决方案

首先,关闭 Stack Overflow 社区.

此外,将图像放入标题元素(在这种情况下

)是完全有效的.这样做是否正确是另一个问题.

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

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

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

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

Code:

<!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>   

解决方案

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

Invalid HTML

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

Valid 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.

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.

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

This is valid HTML:

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

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

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天全站免登陆