html - 是否有任何 HTML 编码约定/样式/标准

标签 html coding-style

<分区>

我的意思是命名 ID、名称、值等?

最佳答案

虽然我认为在命名 HTML 元素时没有单一的、公认的命名约定,但您可能会发现以下文章对您有所帮助。从第二页开始的内容可能最有帮助。祝你好运!

The Meaning of Semantics Take II: Naming Conventions for Class and ID in CSS

这里有一些很好的段落总结了作者试图达到的目的:

A designer might name a column division #leftnav. At first glance this is logical, and in the context of smaller sites, maintained by one or just a few folks, there really aren't a lot of problems with this kind of naming.

However, consider a site the size of AOL or Yahoo, on which large teams of designers and developers manage millions of pages every day. And let's say that a design decision from high on up the corporate ladder is made to move the navigation to the right from its former home on the left side of the screen. Part of the power of CSS is that in a best-case scenario, all that switching the navigation would require is to go into the CSS and swap the column by repositioning it or floating it right instead of left. Save that file and then millions of documents are updated to reflect the change.

But now, millions of documents also have a division with an ID of #leftnav describing a column that appears on the right! Without doing a massive search and replace to change the ID name in the (X)HTML, the document is now very confusing to anyone who views source, or (more importantly) comes in to work on the site.

This is why avoiding presentation and choosing a more relevant description as simple as #nav or #subnav will be more useful in that kind of environment. So, even if it might seem a bit nitpicky, for very large sites we want to try and maintain the power of CSS and the purity of our documents. Smart class and ID names are a major part of that goal.

关于html - 是否有任何 HTML 编码约定/样式/标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/428431/

相关文章:

multithreading - pthread_mutex_lock 返回未测试

java - for 循环内的 if else 语句[java]

javascript - 如何恢复已删除的谷歌地图标记

javascript - 如何将 HTML、CSS 和 Javascript 转换为 EXE?

html - select 的框透明背景在 Chrome 中是否有效?

php - 在 PHP 中编写正则表达式以用 <a> 包装 <img>

.net - My.Computer.FileSystem 和 System.IO.File 之间到底有什么区别

javascript - 如何检测所选文本是否包含在 span 标签中

c++ - 是否有可用的 C++ 样式和/或标准示例文件?

c++ - 如何在 C++ 中创建干净的级联结构?