Does it matter <strong> in <em> or <em> in <strong>?

萝らか妹 提交于 2019-11-29 18:31:04

问题


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?


回答1:


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.




回答2:


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:

<p><em><strong>Some text</em></strong></p>



回答3:


If you care about semantic meaning, you should avoid having both em and strong on an element.

Strong: Renders as strong emphasized text

(via)

If you care about valid HTML, both solutions are fine and valid.




回答4:


According to w3 strong is strong emphasis. That means that em and strong should not be used together semantically as the strong is already an em.

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.




回答5:


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.

EM: Indicates emphasis.

STRONG: Indicates stronger emphasis.

Source

The presentation of phrase elements depends on the user agent. Generally, visual user agents present EM text in italics and STRONG text in bold font. **Speech synthesizer user agents may change the synthesis parameters, such as volume, pitch and rate accordingly.

So beware. Use CSS to acomplish visual effects, not markup.




回答6:


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.



来源:https://stackoverflow.com/questions/2200590/does-it-matter-strong-in-em-or-em-in-strong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!