1

编写有意义的 css .class 和 #id 名称有什么好处?屏幕阅读器会说话以帮助用户理解标签内内容的含义和目的吗?

4

4 回答 4

2

一般来说,它只对开发人员/设计师有益。

于 2010-02-14T07:57:32.400 回答
1

同样,正如您最近关于语义的所有问题一样,答案保持不变:

这一切都取决于相关实体的数据上下文。

如果您的元素包含一个有意义的字段,那么为它分配一个类(即使您不想对其应用 CSS)非常有用,以便轻松定义该特定字段:

<span class="username">Andrew Moore</span>

这样做有以下好处:

  • 它可以轻松识别代码中的字段内容。
  • 它增加了可维护性。
  • 它帮助解析器和第三方应用程序获取该字段的值。

微格式只是一个更大的例子。简而言之,它们是一组预定义的元素和属性,包含一组特定的数据,旨在简化第三方工具的解析。

于 2010-02-14T08:02:33.017 回答
1

Other answers are good, but I will focus on the scraping/third party tools aspect here.

Case 1 is spiders and crawling like search engines. If they parse your page and see something like id="username", they will be more likely to figure out some meaning in that than id="div-style-32". Granted, I'm not sure Google is doing this sort of thing now, but it could be if more people were better about it.

Case 2 is people writing scripts to pull down the HTML and process it in order to extract its content as data. Pretty much anyone who wants to do this can with any markup, its just a matter of how annoying it is. Cleaner and more well described markup allows the scraper script to more easily find the information it needs due to it's increased semantics.

This also includes things like browser extensions or Greasemonkey scripts that allow users to alter the behavior of the site. It will be easier to create these modifications with cleaner markup.

But if you don't want people scraping or modifying your site with client side extension, there is little you can do about from a technical standpoint. You can't stop it, you can only make it more of a pain in the ass. And the benefits of maintainability for the site developers are huge. So really, why not?

In short it makes all the different things you or others could do with your site easier to do.

于 2010-02-14T08:59:40.143 回答
0

你不是为机器做的,而是为人类做的。

如果我们只关心机器,我们仍然会在汇编中编码:)

于 2010-02-14T07:55:52.103 回答