HTML5是否需要具有引用值的属性之间的空格? [英] Does HTML5 requires spaces between attributes that are of quoted values?

查看:114
本文介绍了HTML5是否需要具有引用值的属性之间的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当属性有值时,HTML通常允许在属性之间没有空格,并且这些值被引用。

示例(


在HTML-




 <!DOCTYPE HTML PUBLIC -  / / W3C // DTD HTML 4.01 Transitional // EN
http://www.w3.org/TR/html4/loose.dtd\">

< html>
< head>
< title>没有属性空间< / title>
< meta http-equiv =Content-Typecontent =text / html; charset = iso-8859-1>
< / head>
< body>
< p class =CLASStitle ='TITLE'>< / p>
< / body>
< / html>

查看倒数第三行:

 < p class =CLASStitle ='TITLE'>< / p> 
^^

现在使用这样的HTML块将doctype改为HTML 5(<!DOCTYPE HTML> ),使得实验符合W3C HTML 5标准检查器给出的错误确切地告诉我:


验证输出:1错误



错误第9行,第22列:属性之间没有空格。

 < p class =CLASStitle = 'TITLE' >< / p为H. 
$


所以我认为HTML 5倒退兼容浏览器如何处理HTML和浏览器AFAIK处理这个问题。所以我至少有点慌张。我也有问题来解释(有点不必要的)已经完成的HTML 5规范,因为我确实发现了它(W3C,请参阅 http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes )这并不是说这是(可能也不是必须)是一个错误。

解决方案

您正在阅读已停用的非规范性参考。如果您查看规范(这是规范性的)中的开始标记的定义,它说:


然后,开始标签可能有许多属性,其语法如下所述。 属性必须由一个或多个空格字符相互分隔








因此,我认为HTML 5向后兼容浏览器在现实中处理HTML的方式,而且AFAIK处理这一问题的浏览器很好。


与现实世界标记兼容是一个设计目标,但很多东西已经过时,而忽略属性之间的空间几乎不会故意发生。

HTML does normally allow to have no spaces between attributes when attributes have values and those values are quoted.

Example (Reference/Source):

In HTML-documents no White Spaces between Attributes are needed.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"                                                                 
     "http://www.w3.org/TR/html4/loose.dtd">                                                                                   

<html>                                                                                                                         
  <head>                                                                                                                       
    <title>no attribute space</title>                                                                                          
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">                                                   
  </head>                                                                                                                      
  <body>                                                                                                                       
    <p class="CLASS"title='TITLE'></p>                                                                                         
  </body>                                                                                                                      
</html>                                                                                                                        

See the third-last line:

    <p class="CLASS"title='TITLE'></p>                                                                                         
                   ^^

Now using such HTML chunk changing the doctype to HTML 5 (<!DOCTYPE HTML>), makes the experimental W3C HTML 5 conformance checker give an error exactly there telling me:

Validation Output: 1 Error

Error Line 9, Column 22: No space between attributes.

    <p class="CLASS"title='TITLE'></p>
                    ^

So I thought that HTML 5 is backwards compatible to how browsers deal with HTML in reality and browsers AFAIK deal with this well. So I'm a bit puzzeled at least. I also have problems to decipher the (somewhat needlessly) compilcated HTML 5 specs to be precise at this point because what I did find (W3C again, see http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes) it's not saying that this is (may nor must) be an error.

解决方案

You are reading a discontinued, non-normative reference. If you look at the definition of the start tag in the specification (which is normative) it says:

Then, the start tag may have a number of attributes, the syntax for which is described below. Attributes must be separated from each other by one or more space characters.


So I thought that HTML 5 is backwards compatible to how browsers deal with HTML in reality and browsers AFAIK deal with this well.

Being compatible with real world markup is a design goal, but lots of things have been obsoleted and leaving out the space between attributes is something that almost never occurs intentionally.

这篇关于HTML5是否需要具有引用值的属性之间的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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