我说得有点晚了,但我自己思考的时候看到了这一页。当然,我不知道Facebook和Twitter是如何证明它的价值的,但以下是我自己的思考过程。
最后,我得出结论,这种做法并不是没有语义的(这是一个词吗?)事实上,除了简短和“i is for icon”的良好关联外,我认为当直接的<img>标记不实用时,它实际上是最语义的图标选择。
1. 使用方法与规范一致。
虽然这可能不是W3的主要想法,但在我看来,<i>的官方规范可以很容易地容纳一个图标。毕竟,回复箭头符号是在用另一种方式表示“回复”。它表示一个读者可能不熟悉的技术术语,通常是斜体的。(“在Twitter,这就是我们所说的回复箭头。”)这个词来自另一种语言:象征语言。
如果Twitter使用<i>喊出</i>或<i>[回复的日文字符]</i>(在英文页面上)而不是箭头符号,这将与规范一致。那么为什么不使用<i>[回复箭头]</i>呢?(这里我说的是严格的HTML语义,而不是可访问性,稍后我会讲到。)
据我所知,规范中唯一被图标使用明显违反的部分是“文本跨度”短语(当标签也不包含文本时)。很明显,<i>标记主要用于文本,但与标记的总体意图相比,这是一个非常小的细节。对于这个标记来说,重要的问题不是它所包含内容的格式,而是该内容的含义。
This is especially true when you consider that the line between "text" and "icon" can be almost nonexistent on websites. Text may look like more like an icon (as in the Japanese example) or an icon may look like text (as in a jpg button that says "Submit" or a cat photo with an overlaid caption) or text may be replaced or enhanced with an image via CSS. Text, image - who cares? It's all content. As long as everyone - humans with impairments, browsers with impairments, search engine spiders, and other machines of various kinds can understand that meaning, we've done our job.
So the fact that the writers of the spec didn't think (or choose) to clarify this shouldn't tie our hands from doing what makes sense and is consistent with the spirit of the tag. The <a> tag was originally intended to take the user somewhere else, but now it might pop up a lightbox. Big whoop, right? If someone had figured out how to pop up a lightbox on click before the spec caught up, they still should have used the <a> tag, not a <span>, even if it wasn't entirely consistent with the current definition - because it came the closest and was still consistent with the spirit of the tag ("something will happen when you click here"). Same deal with <i> - whatever type of thing you put inside it, or however creatively you use it, it expresses the general idea of an alternate or set-apart term.
2. <i>标记为图标元素添加语义。
单独携带图标类的另一个选项是<span>,这当然没有任何语义意义。当机器询问<span>它包含什么时,它会说:“我不知道。什么都有可能。”但是<i>标记表示,“我包含了一种不同于通常方式的表达方式,或者可能是一个不熟悉的术语。”这与“我包含一个图标”不同,但它比<span> got!
3.最终,习惯用法就是正确的。
In addition to the above, it's worth considering that machine readers (whether search engine, screen reader, or whatever) may at any time begin to take into account that Facebook, Twitter, and other websites use the <i> tag for icons. They don't care about the spec as much as they care about extracting meaning from code by whatever means necessary. So they might use this knowledge of common usage to simply record that "there may be an icon here" or do something more advanced like triggering a look into the CSS for a hint to meaning, or who knows what. So if you choose to use the <i> for icons on your website, you may be providing more meaning than the spec does.
Moreover, if this usage becomes widespread, it will likely be included in the spec in the future. Then you'll be going through your code, replacing <span>s with <i>'s! So it may make sense to get on board with what seems to be the direction of the spec, especially when it doesn't clearly conflict with the current spec. Common usage tends to dictate language rules more than the other way around. If you're old enough, do you remember that "Web site" was the official spelling when the word was new? Dictionaries insisted there must be a space and Web must be capitalized. There were semantic reasons for that. But common usage said, "Whatever, that's stupid. I'm using 'website' because it's more concise and looks better." And before long, dictionaries officially acknowledged that spelling as correct.
4. 所以我要继续使用它。
So, <i> provides more meaning to machines because of the spec, it provides more meaning to humans because we easily associate "i" with "icon", and it's only one letter long. Win! And if you make sure to include equivalent text either inside the <i> tag or right next to it (as Twitter does), then screen readers understand where to click to reply, the link is usable if CSS doesn't load, and human readers with good eyesight and a decent browser see a pretty icon. With all this in mind, I don't see the downside.