使文本变成斜体的正确方法是什么?我看到了以下四种方法:

<i>Italic Text</i>

<em>Italic Text</em>

<span class="italic">Italic Text</span>

<span class="footnote">Italic Text</span>

<i>

这是“老办法”。<i>没有语义意义,只传达了使文本变成斜体的表示效果。在我看来,这显然是错误的,因为这是非语义的。


<em>

它使用语义标记来实现纯粹的表示目的。它只是发生在默认情况下,<em>以斜体显示文本,所以它经常被那些知道<i>应该避免,但不知道其语义的人使用。并非所有的斜体文本都是斜体,因为它被强调了。有时,它可以是完全相反的,就像一个边注或耳语。


< span class = "斜体”>

This uses a CSS class to place presentation. This is often touted as the correct way but again, this seems wrong to me. This doesn't appear to convey any more semantic meaning that <i>. But, its proponents cry, it is much easier to change all your italic text later if you, say, wanted it bold. Yet this is not the case because I would then be left with a class called "italic" that rendered text bold. Furthermore, it is not clear why I would ever want to change all italic text on my website or at least we can think of cases in which this would not be desirable or necessary.


<跨越阶层= footnote”>

它使用CSS类来实现语义。到目前为止,这似乎是最好的方法,但实际上它有两个问题。

Not all text has sufficient meaning to warrant semantic markup. For example, is italicised text at the bottom of the page really a footnote? Or is it an aside? Or something else entirely. Perhaps it has no special meaning and only needs to be rendered in italics to separate it presentationally from the text preceding it. Semantic meaning can change when it is not present in sufficient strength. Lets say I went along with "footnote" based upon nothing more than the text being at the bottom of the page. What happens when a few months later I want to add more text at the bottom? It is no longer a footnote. How can we choose a semantic class that is less generic than <em> but avoids these problems?


总结

在许多情况下,语义的要求似乎过于繁重,在这些情况下,使某些内容成为斜体的愿望并不意味着具有语义意义。

此外,将样式与结构分离的愿望导致CSS被吹捧为<i>的替代品,当它实际上没有那么有用的时候。所以这让我回到卑微的<i>标签,并想知道这条思路是否是它留在HTML5规范中的原因?

有没有关于这个主题的好博客或文章?也许是那些参与决定保留/创建<i>标记的人?


当前回答

HTML斜体文本以斜体格式显示文本。

<i>HTML italic text example</i>

强调和强烈元素都可以用来增加某些单词或句子的重要性。

<p>This is <em>emphasized </em> text format <em>example</em></p>

当您想要强调文本中的某个点时,而不是当您想要斜体时,应该使用强调标记。

有关更多信息,请参阅本指南:HTML文本格式

其他回答

我不是专家,但我想说,如果您真的想要语义化,您应该使用词汇表(RDFa)。

结果应该是这样的:

<em property="italic" href="http://url/to/a/definition_of_italic"> Your text </em>

Em用于表示(人类将看到它是斜体),属性和href属性链接到斜体的定义(对于机器)。

你应该检查是否有这样的词汇表,也许属性已经存在。

更多关于RDFa的信息,请访问:http://www.alistapart.com/articles/introduction-to-rdfa/

我认为答案是当你想强调时使用<em>。

如果在自己朗读文本时,你发现你用了一个略微不同的声音来强调一个观点,那么它应该使用<em>,因为你想让屏幕阅读器做同样的事情。

如果它纯粹是一个样式的东西,比如你的设计师已经决定你所有的<h2>标题用斜体Garamond看起来更好,那么就没有语义上的理由把它包括在HTML中,你只需要为适当的元素改变CSS。

我看不出有任何理由使用< I >,除非您特别需要支持一些没有CSS的旧浏览器。

也许它没有特殊的含义,只需要用斜体字表示,以便在表示上与前面的文本分开。

如果它没有特殊的意义,为什么它需要从它前面的文本中分离出来?这段文字看起来有点奇怪,因为我无缘无故地把它斜体了。

不过我同意你的观点。对于设计师来说,设计在视觉上变化,但没有意义上的变化是很常见的。我经常在盒子上看到这种情况:设计师会给我们设计包括各种颜色、角落、渐变和阴影组合的盒子,风格和内容之间没有任何关系。

因为这些是在不同地方重用的相当复杂的样式(带有相关的Internet Explorer问题),所以我们创建了像box-1、box-2这样的类,以便我们可以重用这些样式。

不过,将一些文本变成斜体的具体示例太琐碎了,不需要担心。最好把这些细枝末节留给语义狂人们去争论。

你应该针对不同的用例使用不同的方法:

If you want to emphasise a phrase, use <em>. The <i> tag has a new meaning in HTML5, representing "a span of text in an alternate voice or mood". So you should use this tag for things like thoughts/asides or idiomatic phrases. The spec also suggests ship names (but no longer suggests book/song/movie names; use <cite> for that instead). If the italicised text is part of a larger context, say an introductory paragraph, you should attach the CSS style to the larger element, i.e. p.intro { font-style: italic; }

我会说使用<em>来强调内联元素。为块元素(如文本块)使用类。不管是不是CSS,文本都必须被标记。不管它是为了语义还是视觉辅助,我假设你会用它来做一些有意义的事情……

如果出于任何原因要强调文本,则可以使用<em>,或一个使文本斜体的类。

有时候打破规则是可以的!