这是我的问题.
HTML
<div id="content">
<h1>Headline</h1>
<p>First paragraph that needs to be yellow.</p>
<p>Second paragraph that need not change. :) </p>
<p>Third paragraph that need not change. :) </p>
</div>
Run Code Online (Sandbox Code Playgroud)
如果我使用#content p:first-child {color:yellow; }它不起作用,因为p不是第一个孩子content...... h1是第一个出生的.
如何在不触及HTML代码的情况下执行此操作?
谢谢!
一切都很好,克里斯
ohm*_*ama 20
一个css3解决方案
#content > p:first-of-type { color: yellow; }
Run Code Online (Sandbox Code Playgroud)
Nav*_*mad 14
这是最好的方法:
$('#content p:first').css('color', 'yellow');
Run Code Online (Sandbox Code Playgroud)