列表中的 strong 元素变为斜体字,而不是通常的粗体字,兴许如许界说一个派生抉择器:
li strong { font-style: italic; font-weight: normal; }请留心标记为 <strong> 的蓝色代码的上下文相关:
<p><strong>我是粗体字,不是斜体字,因为我不在列表傍边,以是这个规定对我不起浸染</strong></p> <ol> <li><strong>我是斜体字。这是由于 strong 元素位于 li 元素内。</strong></li> <li>我是正常的字体。</li> </ol>在上面的例子中,只有 li 元素中的 strong 元素的技俩为斜体字,无需为 strong 元素定义额外的 class 或 id,代码更为简捷。
再看看下面的 CSS 划定:
strong { color: red; } h2 { color: red; } h2 strong { color: blue; }下面是它施加影响的 HTML:
<p>The strongly emphasized word in this paragraph is<strong>red</strong>.</p> <h2>This subhead is also red.</h2> <h2>The strongly emphasized word in this subhead is<strong>blue</strong>.</h2>
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/css-tool/t52338.shtml