对html标签使用大写字母不好吗? [英] Is it bad to use uppercase letters for html tags?

查看:179
本文介绍了对html标签使用大写字母不好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最佳做法是什么?

 < HTML>或< html> 

为什么我们应该坚持一个特定的情况?



然而,所有浏览器似乎都解释了这两种情况,并返回了预期的输出。 是xHTML的遗留物,明确要求它。



另一方面,普通的旧HTML不遵循XML的严格结构要求,因此不具有固定的使用案例的要求

然而,开发人员往往坚持以小写字母作为惯例,主要原因是在工作时阅读起来更容易在上面,更容易打字。但这只是一个惯例;没有任何东西强迫它。如果你现在有大写标签的代码,它们就可以工作,而且还有一些阻碍你继续以这种方式编写标签。

另外一件事要注意:在所有浏览器中,当浏览器加载HTML文档并解析它时,它会将其转换为DOM(文档对象模型)。如果您随后使用浏览器的内置开发人员工具来检查网站,则在查看DOM时,DOM中的所有元素都将显示为小写,无论它们是如何写入实际源代码的。



因此,如果坚持小写,您会发现使用开发人员工具更容易,因为您在DOM视图中看到的代码将与源代码。


What is the best practice?

 <HTML> or <html>

And why we should stick with one particular case?

However all browsers seems to interpret both cases and returns the expected output.

解决方案

The lower-case "requirement" is a legacy of xHTML, which explicitly required it.

Plain old HTML on the other hand does not follow the rigid struct requirements of XML, and does not therefore have the fixed requirement for use of case

However developers have tended to stick with lower case as a convention anyway, mainly on the grounds that it's a lot easier to read when you're working on it, and easier to type. But it is only a convention; there's nothing forcing it. If you have existing code with upper case tags, they will work, and there's nother stopping you continuing to write your tags that way.

One other thing to be aware of though: In all browsers, when the browser loads the HTML document and parses it, it converts it into a DOM (Document object model). If you then use the browser's built-in developer tools to inspect the site, when you view the DOM, all elements in the DOM will be shown as lower case, regardless of how they were written in the actual source code.

For this reason, if you stick with lower case, you'll find it easier to work with the developer tools, because the code you see in the DOM view will be more consistent with the source code you've written.

这篇关于对html标签使用大写字母不好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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