重要吗在或在<强>?强>
重要吗
<p><strong><em>Some text</em></strong></p>
中的
或
中的 ?
<p><em><strong>Some text</strong></em></p>
哪个在语义上是正确的并且更容易理解?
更新:
屏幕阅读器在这两种情况下会如何表现?
Does it matter <strong>
in <em>
<p><strong><em>Some text</em></strong></p>
or <em>
in <strong>
?
<p><em><strong>Some text</strong></em></p>
Which is semantically correct and more accessible?
Update:
How screen reader would behave in both situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
语法正确,但语义不正确。
可以说是
的“高阶”形式。如果您正在寻找
和
的效果,请使用 CSS。请记住,不要因为元素的外观而选择元素,而是因为它们的含义。
Syntactically correct but not semantically correct.
<strong>
is an "higher order" form, so to speak, of<em>
. If you're looking for the effect of<b>
and<i>
, use CSS. Remember to not choose elements because of how they look but what they mean.只要您不混淆结束标签的顺序,您列出的两种方式在标记方面都是完全正确的。这是不正确的:
Both ways you have listed are perfectly correct markup-wise, as long as you're not mixing up the order of the closing tags. This would be incorrect:
根据 w3
strong
是强烈强调。这意味着em
和strong
不应在语义上一起使用,因为strong
已经是em
。如果您认为强烈强调应该是粗斜体,我认为您应该添加一个 css 声明,在其中将强调样式设置为粗体斜体。
According to w3
strong
is strong emphasis. That means thatem
andstrong
should not be used together semantically as thestrong
is already anem
.If you believe that strong emphasis should be bold italic I think you should just add a css declaration in which you style the strong as bold italic.
如果您关心语义,则应避免在元素上同时使用
em
和strong
。(via)
如果您关心有效的 HTML,那么这两种解决方案都很好且有效。
If you care about semantic meaning, you should avoid having both
em
andstrong
on an element.(via)
If you care about valid HTML, both solutions are fine and valid.
从视觉效果的角度来看,这并不重要。
在语义上,这很重要,因为您在同一元素(某些文本)中使用强调和强烈强调。这与在某些地方使用
h1
相同,只是因为您想要大文本,而不是因为它们是标题。来源
所以要小心。使用 CSS 来完成视觉效果,而不是标记。
In a visual effect perspective, it doesn't matter.
In semantic meaning, it matters since you're using emphasis and strong emphasis in the same element (Some text). It's the same as using
h1
in some places just because you want big texts and not because they're titles.Source
So beware. Use CSS to acomplish visual effects, not markup.
在 (X)HTML5 中,定义/含义为:
em
:表示其内容的重音强调(改变句子的含义);强
:代表其内容的强烈重要性(不会改变句子的含义)。因此原则上这些元素可以一起使用。
要获得想法,请考虑大声朗读文本(不过取决于语言):
em
可能会改变语调(重音),strong
可能会增加响度。我认为从语义上讲,如果您使用
foo
或foo
;至少我在规范中找不到任何相关内容。In (X)HTML5, the definitions/meanings are:
em
: represents stress emphasis of its contents (changes meaning of sentence);strong
: represents strong importance for its contents (doesn't change meaning of sentence).So these elements can be used together in principle.
To get an idea, think of reading a text out loud (depends on language, though):
em
might change the intonation (stress),strong
might increase loudness.I think semantically it makes no difference if you use
<strong><em>foo</em></strong>
or<em><strong>foo</strong></em>
; at least I couldn't find anything related in the specification.