html 属性和值之间有空格吗?
他们被允许吗?它们适用于所有浏览器吗?
例子:
<div role = "region"
id = "some-id"
class = "a-class another-class">
Are they allowed? and do they work with all browsers?
Example:
<div role = "region"
id = "some-id"
class = "a-class another-class">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,任意数量的空格都是允许的,并且适用于所有浏览器。
来自 HTML5 生活标准的属性部分(未引用),单引号和双引号属性值语法:
一个考虑因素 - 这会增加页面大小,因此如果带宽并且性能是问题,请尝试限制使用的空白量。
Yes, any amount of whitespace is allowed and will work in all browsers.
From the Attributes section of the HTML5 living standard on unquoted, single-, and double-quoted attribute value syntax:
One consideration - this will add to the page size, so if bandwidth and performance are concerns, try to limit the amount of whitespace you use.
是的,它们是,并且它们将在所有主要浏览器中工作,尽管我认为包含不必要的空白应该被认为是不好的做法,因为它毫无意义地增加了文档的大小。
HTML、XHTML、XML 等都是 SGML 的变体,所以如果您想知道一般情况下允许/不允许什么,请查看该规范。您应该始终通过 W3C 标记验证器传递所有文档,以确保它们有效。
Yes they are, and they will work in all major browsers, although I would say it should be considered bad practice to include unnecessary white-space as it pointlessly increases the size of the document.
HTML, XHTML, XML and others are all variants of SGML, so if you want to know what is/isn't allowed in general, have a look at that specification. You should always pass all your documents through the W3C markup validators to ensure they are valid.
是的,这是完全有效的标记。所有浏览器都能很好地处理空白。
任何时候您有任何困惑,您可以在官方 W3 验证服务验证您的代码:
Yes, it is perfectly valid markup. Whitespace is handled nicely by all browsers.
Any time you have confusion, you can validate your code at official W3 validation service: